Release cannot move for approval unless Approved Change is attached
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 07:21 AM
Hi, please help on this scenario:
Release record cannot be moved to 'Awaiting Approval' unless an approved Change Request is associated to it.
I have the below BR but it is not working.
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 07:25 AM
I also used this script but did not work either. Please help. Thanks.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 07:26 AM
(function executeRule(current, previous /*null when async*/) {
// Check if the state is changing to 'Awaiting Approval' or other relevant states
if (current.state == 'awaiting_approval' || current.state == 'work_in_progress' || current.state == 'testing_qa' || current.state == 'deploy_launch') {
// 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.addErrorMessage('Release cannot move to the selected state without a Change Request.');
} else {
// Change Request found, check if it is approved
if (changeRequest.approval == 'approved') {
// Change Request is approved, allow state change
// Add any additional actions as needed
} else {
// Change Request not approved, prevent state change
current.setAbortAction(true);
gs.addErrorMessage('Release cannot be approved until the associated Change Request is approved.');
}
}
}
})(current, previous);
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 07:27 AM
(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);