Struggling with Business Rule to Update Change Request Approval Status

Lisa Goldman
Kilo Sage

Hello,

 

This Business Rule is triggered from the syapproval_approver table. We want the "Approval" field value on the Change Request to change to "Approved" when an approval record is marked as approved in the approval table.

I’m struggling to get this Business Rule to work and would appreciate any suggestions.  Thank you,

 

Example Change Request:

LisaGoldman_0-1724880381449.png

 

 

Business Rule:

 

LisaGoldman_1-1724880454939.png

 

LisaGoldman_2-1724880492596.png

 

(function executeRule(current, previous /*null when async*/ ) {
    // Ensure the sysapproval field is not empty and is associated with a change_request
    if (!current.sysapproval.isNil() && current.sysapproval.sys_class_name == 'change_request') {

        var changeRequest = new GlideRecord('change_request');
        if (changeRequest.get(current.sysapproval.sys_id)) {
          
			changeRequest.approval = 'Approved';
			changeRequest.justification = 'This change request has been approved';
			changeRequest.update();

         }
    }
})(current, previous);

 

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

Hi Lisa,

The approval field value for 'Approved' is likely 'approved', so that would explain why this isn't getting set.  Are you seeing the justification populated on these past test cases?  You can troubleshoot the script and trigger by adding some gs.info lines to the script to confirm that it is triggered when expected, then see which if conditions are satisfied... so you can see where the script is going wrong.  You probably also want to add to your Filter Conditions or another condition on the first if statement something like State changes to Approved so that this isn't triggered if the approval record is rejected or otherwise updated without being approved.

Hi Brad,

Thank you for helping.  The justification got populated, but the approval field did not.  I could not find out why it did not get update.

Hi Brad,

I figured it out.  There was another business rule the prevent it from update the value.  Thanks