Update sysapproval_approver table with a field from change_request

brown9394
Tera Expert

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! 

1 ACCEPTED SOLUTION

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.

View solution in original post

5 REPLIES 5

SanjivMeher
Kilo Patron
Kilo Patron

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.

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? 

find_real_file.png

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.

Thank you, that worked!