how to auto create child record when multiple mrvs are added

alishamulan
Tera Contributor

alishamulan_0-1746516231578.png

hello, 

i want to write a businees rule i have created   mrvs in record producer
when i add rows then its child record must also be created in mrvs , how can i achieve this?

how to link child to parent in business rule

1 ACCEPTED SOLUTION

mohdarbaz
Kilo Guru

Hi @alishamulan ,

 

you can use below sample script to link child to parent in BR.

 

(function executeRule(current, previous /*null when async*/) {
    // Query the child table
    var grChild = new GlideRecord('child_table');
    grChild.addQuery('parent_reference_field', current.sys_id);
    grChild.query();
   
    // Loop through each child record and update the parent reference field
    while (grChild.next()) {
        grChild.parent_reference_field = current.sys_id;
        grChild.update();
    }
})(current, previous);
 

This script ensures that each child record is linked to its parent record whenever the parent record is inserted or updated.

 

If my response helped, please mark it correct/helpful and close the thread so that it benefits future readers.

 

Regards,

Mohd Arbaz.

View solution in original post

5 REPLIES 5

Gaurav Rathaur
Kilo Guru

Hi @alishamulan,

 

If my response was also helpful, please mark it as the correct answer and close the thread. This will help others who come across the same issue.

Thanks!
Gaurav Rathaur