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

Saurav11
Kilo Patron
Kilo Patron

Hello, 

Is "sn_hr_core_task" the parent table if yes then use the below script:-

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

 

Please mark answer correct/helpful based on Impact

Mohith Devatte
Tera Sage
Tera Sage

hello @absnow ,

If your business rule is on HR task table you need to glide record case table in order to get the date value like below

note : Use variables.u_effective_date if thats a variable from variable editor or if it is from the form then you can use the below script

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

    var ga = new GlideRecord("sn_hr_core_case");
    ga.addQuery('sys_id',current.parent);
    ga.query();
    if(ga.next()){
var gr= new GlideRecord('sn_hr_core_task');
gr.addQuery('sys_id',current.sys_id);
gr.query();
if(gr.next())
{
 gr.u_effective_from =ga.u_effective_date;
gr.update();
}
    }
})(current, previous);


Please mark my answer correct if it helps you

Hello @Mohith Devatte ,

In parent table date is there , but "Effective Form" is not set any value from parent table.

"Effective Form" field is custom view field of task table. 

could you please update ?

BR is running on After insert/ update on task table .

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

@absnow  so your BR is on HR task table or task table ?

if your BR is on HR task table 

try with this 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();
}