Workflow or BR for Release to be moved to 'Awaiting Approval' when Change is raised/attached to it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2024 07:56 AM
Hi, I need help with creating a flow designer or business rule for this scenario:
Release record cannot be moved to 'Awaiting Approval' state unless a Change Request is attached or raised under it.
I've been trying to figure out how to do it using Flow Designer but it seems like I am just running around in circles.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2024 09:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2024 10:35 AM
Hello @tindiz ,
Please give a try to the script below and let me know, also I have added logs so we could get an idea like how much code is working,
(function executeRule(current, previous /*null when async*/) {
// Log the start of the script
gs.log('Business Rule Script Execution Started for Release: ' + current.number);
// Check if there is a related Change Request
var changeRequest = new GlideRecord("change_request");
changeRequest.addQuery('release', current.sys_id);
changeRequest.query();
if (!changeRequest.hasNext()) {
// No Change Request found, prevent state change
current.setAbortAction(true);
gs.log('Release cannot move to the selected state without a Change Request.');
gs.addErrorMessage('Release cannot move to the selected state without a Change Request.');
} else {
// Change Request found, log and check if it is approved
gs.log('Change Request found for Release: ' + current.number);
if (changeRequest.approval == 'approved') {
// Change Request is approved, allow state change
// Add any additional actions as needed
gs.log('Change Request is approved. Allowing state change for Release: ' + current.number);
} else {
// Change Request not approved, prevent state change
current.setAbortAction(true);
gs.log('Release cannot be approved until the associated Change Request is approved for Release: ' + current.number);
gs.addErrorMessage('Release cannot be approved until the associated Change Request is approved.');
}
}
// Log the end of the script
gs.log('Business Rule Script Execution Completed for Release: ' + current.number);
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2024 05:53 PM
I got this message when I try to move the Release record to 'Awaiting Approval' while Change Request has not been raised yet.
And when I try to raise a Change Request and gets it in 'Approved' state and tries to move the Release to 'Awaiting Approval' I am still getting the above message.