Struggling with Business Rule to Update Change Request Approval Status
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2024 02:29 PM
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:
Business Rule:
(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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2024 04:28 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2024 07:55 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2024 10:02 PM
Hi Brad,
I figured it out. There was another business rule the prevent it from update the value. Thanks