How to write a script to update related record on same table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 03:07 AM
Hi All,
I had a requirement to update the contract details of related contracts records when the current manager changes .
I have written a after update business rule. I am querying the parent contract with the current record to get the related contract records.
Business written on -ast_contract
condition- manager changes
(function executeRule(current, previous /*null when async*/ ) {
var cntno = current.vendor_contract;
var cnt = new GlideRecord("ast_contract");
cnt.addEncodedQuery('parent_contract='+cntno);
//cnt.addQuery("vendor_contract", cntno);
cnt.query();
while(cnt.next()) {
cnt.u_director = cnt.u_manager.u_director;
cnt.u_vice_president = cnt.u_manager.u_vp;
cnt.approver = cnt.u_manager;
cnt.update();
gs.log("record updated");
}
// Add your code here
})(current, previous);
But this code is not working
Anyone can please help
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 03:16 AM
HI @Sangeetha8
You don't need to glide on the same table. Just right before BR where the condition is manager changes and you can set the values under Action setion
Hit helpful if this resolves your query.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 04:01 AM
Hi Need to do the updation on related records example child contracts

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 04:25 AM
Hi @Sangeetha8 adjusted the code accordingly
var cntno = current.vendor_contract;
var cnt = new GlideRecord("ast_contract");
cnt.addEncodedQuery('parent_contract='+cntno);
//cnt.addQuery("vendor_contract", cntno);
cnt.query();
while(cnt.next()) {
cnt.u_director = current.u_manager.u_director; // updating current record value to ast_contract record
cnt.u_vice_president = current.u_manager.u_vp;
cnt.approver = current.u_manager;
cnt.update();
gs.log("record updated");
}
Harish