The CreatorCon Call for Content is officially open! Get started here.

Business rule to restrict approval

Phanideepthi
Tera Contributor

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

 

Phanideepthi_0-1682682289588.png

Here the issue is it is working for only one check box the or condition is not working. Please help to achieve this.

 

Thanks

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@Phanideepthi 

share script here

Also any one should be checked then you should compare with true and not false

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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);
}

@Phanideepthi 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks Ankur, but my issue is even If I check one checkbox and then approve the RITM I am getting the error message.

Phanideepthi_0-1682689798334.png

Only working for first condition means when I select the revoked check box