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

Good morning @Brian Lancaster 

Here is the list layout and when I clicked on the parent number, it took me to the parent record.

find_real_file.png

 

In the child table, the Parent field is pointing to the Task table

find_real_file.png

 

Here is the BR:

find_real_file.png

 

 

Here is the code, could you please modify the code to see if it works so that I can learn from it.

(function executeRule(current, previous /*null when async*/ ) {

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

current.meeting_start_date = gr.meeting_start_date;
current.meeting_end_date = gr.meeting_end_date;
current.update();

}

})(current, previous);

Your add query should be 

gr.addQuery('sys_id', current.parent)

@Brian Lancaster 

I'm using Script Background to test the code to see if it runs.  I got the following error. What does it mean?  

Evaluator: com.glide.script.fencing.MethodNotAllowedException: Function print is not allowed in scope x_531698_bod_syst. Use gs.debug() or gs.info() instead
   Caused by error in script at line 3

      1: var gr = new GlideRecord('x_531698_bod_syst_director_requests'); 
      2: gr.query();
==>   3: gs.print(gr.number);
      4: 
 

gs.Print(); is not allowed in scopped app.

 

please use gs.info(gr.number);

var gr = new GlideRecord('you table');
gr.addQuery('sys_id',current.parent);
gr.query();
if(gr.next()){

current.meeting_start_date = gr.meeting_start_date;
current.meeting_end_date = gr.meeting_end_date;
current.update();

}

Please try the above code