Issue #24592 - add bomhead record in bomitem trigger if one does not exist
authorkrauseo <krauseo@emseal.com>
Thu, 25 Sep 2014 14:08:02 +0000 (10:08 -0400)
committerkrauseo <krauseo@emseal.com>
Thu, 25 Sep 2014 14:08:02 +0000 (10:08 -0400)
foundation-database/public/trigger_functions/bomitem.sql

index a97c20f..bd4baf9 100644 (file)
@@ -41,6 +41,17 @@ BEGIN
 
     PERFORM deleteBOMWorkset(_bomworksetid);
 
+    -- Create bomhead record if one does not exist
+
+    SELECT bomhead_id INTO _bomheadid
+    FROM bomhead
+    WHERE (bomhead_item_id=NEW.bomitem_parent_item_id);
+
+    IF (NOT FOUND) THEN
+      INSERT INTO bomhead (bomhead_item_id, bomhead_batchsize, bomhead_rev_id)
+                   VALUES (NEW.bomitem_parent_item_id, 1, -1);
+    END IF;
+
     -- Set defaults
     NEW.bomitem_rev_id := COALESCE(NEW.bomitem_rev_id, -1);
     NEW.bomitem_booitem_seq_id := COALESCE(NEW.bomitem_booitem_seq_id, -1);