Business rule to restrict approval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2023 04:51 AM
Hi All,
There is a catalog item where once the request is submitted and waiting for approval. there are two check boxes on RITM form where any one should be selected before approving. here is the script
Here the issue is it is working for only one check box the or condition is not working. Please help to achieve this.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2023 04:55 AM
share script here
Also any one should be checked then you should compare with true and not false
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2023 05:35 AM
Hi Ankur,
Here is the script
(function executeRule(current, previous /*null when async*/ ) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('sys_id', current.sysapproval);
ritm.query();
if (ritm.next()) {
// if (ritm.variables.this_variance_is_effective_within_the_following_duration == 'false' ||
if((ritm.variables.this_variance_is_effective_until_revoked == 'false') || (ritm.variables.this_variance_is_effective_within_the_following_duration == 'false') && ritm.cat_item == 'Server Variance') {
gs.addErrorMessage('Mandatory variables Duration of Variance must be filled on the Requested Item.');
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2023 06:20 AM
basically you want to show error message when either of the checkbox is selected
update as this
(function executeRule(current, previous /*null when async*/ ) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('sys_id', current.sysapproval);
ritm.addQuery('cat_item.name', 'Server Variance');
ritm.query();
if (ritm.next()) {
if(ritm.variables.this_variance_is_effective_until_revoked.toString() == 'true' || ritm.variables.this_variance_is_effective_within_the_following_duration.toString() == 'true') {
gs.addErrorMessage('Mandatory variables Duration of Variance must be filled on the Requested Item.');
current.setAbortAction(true);
}
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2023 06:57 AM
Thanks Ankur, but my issue is even If I check one checkbox and then approve the RITM I am getting the error message.
Only working for first condition means when I select the revoked check box