This article explains how to copy children's entity records when the user clicks on a copy action on a parent record. For reference, the ProductRetailDemo model is used and will copy the Items linked to a Product.


First, create a procedure in the Database-

CREATE OR REPLACE PROCEDURE semarchy_product_retail_mdm.copyproc(v_currentLoadId IN numeric(38) , v_copied_from IN numeric(38) , v_id IN numeric(38))

    LANGUAGE plpgsql

AS $procedure$

    BEGIN

INSERT INTO sa_item  (B_LOADID, B_CLASSNAME, B_CREDATE, B_CREATOR, upc , f_product , color,color_description,f_item_size)

    SELECT v_currentLoadId, 'Item', current_date, 'semadmin', concat(upc,'c')  , v_id, color,color_description, f_item_size

    FROM GD_item X

    WHERE X.f_product  = v_copied_from ;

    END;

$procedure$

;

This procedure takes Loadid, CopiedFrom id as well as the newly created parentId as arguments. It will take all existing GD records from the child entity that have the copied parent Id as a foreign key, and will insert the same records into the source table, 

Here, the Product is the parent entity and the Item is a child. After this, call the procedure(copyproc) in the stepper - Event - Collection Step - Copy Child (each)





Procedure (same name as in the database)- copyproc


Arguments:

 

Create the DataBase function- copyproc(procedure)


 

Add Copy action in ProductActionSet-

 

For reference below are some screenshots of the same-

Copied Bambina Boots record.


The child entity record is also got copied and its UPC got concatenated with 'c' at last.