Have to set field value from parent to child table field

abirakundu23
Mega Sage

Hello All/ @Ankur Bawiskar ,

 I have a field on parent case table is "Effective date", we want to set same field value on child task table "Effective From".

After insert/update on task table, but is not set on child table field. Could you please guide ?

(function executeRule(current, previous /*null when async*/) {
// gs.info("current parent :" +current.parent);
// current.u_effective_from = current.parent.variables.u_effective_date;
    var ga = new GlideRecord("sn_hr_core_task");
    ga.addQuery('sys_id',current.parent);
    ga.query();
    if(ga.next()){
    //current.u_effective_from = current.u_effective_date;
  current.u_effective_from = current.parent.variables.u_effective_date;
 current.update();
    }
})(current, previous);

8 REPLIES 8

Hello Mohith,

HR task table.

@absnow  then please trythis script it should work as parent field stores the HR case record as parent

Just replace your effective date field name in below script

var gr= new GlideRecord('sn_hr_core_task');
gr.addQuery('sys_id',current.sys_id);
gr.query();
if(gr.next())
{
 gr.your_effective_field_back_end_name=current.parent.u_effective_date;
gr.update();
}
   

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you would require before insert BR on child HR task table sn_hr_core_task

This would work during insertion

Script:

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

	// Add your code here
	current.u_effective_from = current.parent.u_effective_date;

})(current, previous);

If you want the Child date to change based on parent variable/field change then you can use after update BR on HR Case table and query Child table and update it

regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@absnow 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader