- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2018 03:06 PM
Hello,
I have a requirement to update a field on a sysapproval_approver table with a field from change_request table - anytime this changes. I'm trying to do this by using a BR on change_request to run after / update but no luck so far.
Condition: current.close_code.changes()
Script:
(function executeRule(current, previous /*null when async*/) {
var chg = new GlideRecord('sysapproval_approver');
chg.addQuery('sys_id', current.sys_id);
chg.query();
if(chg.next()) {
chg.u_close_code = current.close_code;
chg.update();
}
})(current, previous);
Any help would be great!
Thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2018 03:29 PM
Use below script.
(function executeRule(current, previous /*null when async*/) {
var chg = new GlideRecord('sysapproval_approver');
chg.addQuery('sysapproval', current.sys_id);
chg.addQuery('state', 'requested');
chg.query();
while(chg.next()) {
chg.u_close_code = current.close_code;
chg.update();
}
})(current, previous);
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2018 03:11 PM
Please use below script
(function executeRule(current, previous /*null when async*/) {
var chg = new GlideRecord('sysapproval_approver');
chg.addQuery('sysapproval', current.sys_id);
chg.query();
while(chg.next()) {
chg.u_close_code = current.close_code;
chg.update();
}
})(current, previous);
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2018 03:25 PM
Hello, so this worked but I'm seeing another issue. The close_code on change request changes with every approval, for example I have posted a screenshot here. So if first approval has the close code of the 'successful', the second approval will have the 'unsuccessful'. This updates the previous approval close code. Is there a way to only update the close code for new approval, and not past approved/rejected approvals?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2018 03:29 PM
Use below script.
(function executeRule(current, previous /*null when async*/) {
var chg = new GlideRecord('sysapproval_approver');
chg.addQuery('sysapproval', current.sys_id);
chg.addQuery('state', 'requested');
chg.query();
while(chg.next()) {
chg.u_close_code = current.close_code;
chg.update();
}
})(current, previous);
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2018 03:40 PM
Thank you, that worked!