antin_s
ServiceNow Employee

Hi Edwin,



I am not sure about the Script, but I dont think it would solve your user case. You use case is much simpler than that. The below script would solve your use case. I have updated the same in your other thread also.



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




var outputDate = current.end_date;


var children = new GlideRecord('table_b');


children.addQuery('table_a', current.table_a);


children.addQuery('sys_id', '!=', current.sys_id);


children.query();


while(children.next()){


if(outputDate < children.end_date)


outputDate = children.end_date;


}



var parentRec = new GlideRecord('table_a');


if(parentRec.get(current.table_a)){


parentRec.end_date = outputDate;


parentRec.update();


}




})(current, previous);




Hope this helps. Mark the answer as correct/helpful based on impact.



Thanks


Antin