Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Approval Notification exclusions not working

Venjamin
Tera Contributor

I am trying to exclude a notification. I set up a secondary approval notification for a specific item, but I can't seem to exclude items from the normal approval notification. I added the following: 

 

 

 

// Seems I should be able to put this logic in the condition builder (Approval for.Request Item.Item is Not 'Contractor Monthly Review') but not working
answer = true;
// 'Contractor Monthly Review' request item sys_id = 16172199db199410e4221fdc139619f2
if (current.sysapproval.cat_item == '16172199db199410e4221fdc139619f2' || current.sysapproval.cat_item == '760d2315db491450e4221fdc13961986' || current.sysapproval.cat_item == '7cc3b519893e08690fb70bacc5cba104d') {
    answer = false;
}

 

 

And yet I'm still firing 2 approval notifications. Any specific thing you're seeing that I might have missed?

1 ACCEPTED SOLUTION

I see the problem, sysapproval is a reference to the task table which does not have cat_item on it. So we need to do a lookup with GlideRecord.

 

var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id', current.sysapproval);
gr.query();
if (gr.next()) {//check to verify this isa catalog item
    if (gr.cat_item == '16172199db199410e4221fdc139619f2' || gr.cat_item == '760d2315db491450e4221fdc13961986' ||
        gr.cat_item == '7cc3b519893e08690fb70bacc5cba104d') {//do not sent notification
        answer = false;
    } else { //send notification when not one of the above catalog items
        answer = true;
	}
}
else { //send notification when not a catlog item
	answer = true;
}

 

View solution in original post

6 REPLIES 6

Brian Lancaster
Kilo Patron

Try this:

// Seems I should be able to put this logic in the condition builder (Approval for.Request Item.Item is Not 'Contractor Monthly Review') but not working
// 'Contractor Monthly Review' request item sys_id = 16172199db199410e4221fdc139619f2
if (current.sysapproval.cat_item == '16172199db199410e4221fdc139619f2' || current.sysapproval.cat_item == '760d2315db491450e4221fdc13961986' || current.sysapproval.cat_item == '7cc3b519893e08690fb70bacc5cba104d') {
    answer = false;
}
else {
    answer = true;
}

 

Unfortunately no, it still fired both approvals. 

I see the problem, sysapproval is a reference to the task table which does not have cat_item on it. So we need to do a lookup with GlideRecord.

 

var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id', current.sysapproval);
gr.query();
if (gr.next()) {//check to verify this isa catalog item
    if (gr.cat_item == '16172199db199410e4221fdc139619f2' || gr.cat_item == '760d2315db491450e4221fdc13961986' ||
        gr.cat_item == '7cc3b519893e08690fb70bacc5cba104d') {//do not sent notification
        answer = false;
    } else { //send notification when not one of the above catalog items
        answer = true;
	}
}
else { //send notification when not a catlog item
	answer = true;
}

 

This worked perfectly. Do you think I could do the same thing, except with the approval group? I ran into a small issue where the main approvals still need to fire for this same catalog item, and if I block the catalog item I get hit with a baby/bathwater situation. Essentially, I have 3 approvals for this record. 1 and 2 are standard management approvals, and a 3rd is an external group approval that has different formatting and requirements. 


Originally, I just had the notification only firing when it went to the specific external approval group, and needed to mute the "standard" approval going to that approval group.