How to copy fields value from Parent to Child form?

Erica2
Tera Contributor

Hello everyone,

My use case is in my parent form, I have meeting start and end date fields where the end user select the dates. 

I also have the same fields in my child form.  How do I copy the start and end date from the parent to child form when the record is insert or update so that those dates will show up in the child form as well?

Thanks

 

1 ACCEPTED SOLUTION

try this is scripts background.

var gr = new GlideRecord('x_531698_bod_syst_director_requests'); 
gr.addQuery('sys_id', 'sysid'); //repleace sysid with a sysid from one of your parent records.
gr.query();
if (gr.next()){
   gs.info(gr.number);
}

View solution in original post

19 REPLIES 19

Brian Lancaster
Tera Sage

Use an after insert/update business rule on the parent table that does a gliderecord query to lookup the child record and updates it.

Tony Chatfield1
Kilo Patron

Hi, As Brian indicated you would use an after business rule to update the child record once the parent record values have been updated/committed to the database.
This will require a glide query to find the child record(s) and you can then set the child values based on 'current' values and would be something like (untested)

var gr = new GlideRecord('yourTable');
//Normally only active children would be updated
gr.addActiveQuery();
//Assumes the 'parent' field is on the current record and a relationship to the children
gr.addQuery('parent', current.sys_id);
gr.query();

//Now itterate through all child records
while(gr.next()) {

gr.yourTargetField1 = current.yourSourceField1;
gr.yourTargetField2 = current.yourSourceField2;

gr.update();

}

 

ursnani
Giga Guru

Write a Before Insert BR as below.

var gr = new GldieRecord('child_table');
gr.addQuery('parent',current.parent);
gr.query();
if(gr.next()){

current.start_date(date field on Child table) = gr.start_date;(date field on Parent table) 
current.end_date(date field on Child table) = gr.end+date;date field on Parent table)
current.update();

}

Erica2
Tera Contributor

I'm really sorry for not being clear.  I need to trigger a business rule when there is an insert/update on the child table. Then copy the values from the parent to the child table.