Send notification only if updated_by is NOT a member of a specific group (or has a specific role)

Marcel H_
Tera Guru

I am looking for a way, perhaps through advanced conditions on an email notification to send only when the person updating the record is not a member of a specific group, or has a specific role.

Basically I have a group that needs to be notified any time a ticket is updated in the Additional Comments, Work Notes or Close Notes fields, but only if it is someone other than members of their group doing the updates. I'd like it to be dynamic rather than a bunch of "Updated by IS NOT X" conditions since group membership does change occasionally, and I don't want to have to update a large number of notifications if that does happen.

Any help is greatly appreciated. Thanks!

1 ACCEPTED SOLUTION

Uncle Rob
Kilo Patron

Sure thing, boss!
Remember, you have more than 1 way to trigger a Notification.  Most commonly people use the condition  builder logic, but that can run out of steam with just a little complexity. 

The other solid option is to make Notifications trigger on an event (go to the Advanced view of the notification form and see that there's a When to Trigger choice list).  So you go to your Event Registry and create a new event for the situation (notify.nonmember.update lets say).

Now you have a business rule capture the conditionality.
"When an incident is updated...." and in your script something like...

var membership = new GlideRecord('sys_user_grmember');
membership.addQuery('user',gs.getUser());
membership.addQuery('group',<sys_id of group in question>);  //(or current.assignment_group if you want scalability)
membership.query();

if (membership.next()){
  return;
} ele {
  gs.eventQueue('notify.nonmember.update',current,parm1,parm2) //you can send 2 parns with each eventQueue call
}

 

Now just build your notification to be fired by the notify.nonmember.update event.

View solution in original post

6 REPLIES 6

Uncle Rob
Kilo Patron

Sure thing, boss!
Remember, you have more than 1 way to trigger a Notification.  Most commonly people use the condition  builder logic, but that can run out of steam with just a little complexity. 

The other solid option is to make Notifications trigger on an event (go to the Advanced view of the notification form and see that there's a When to Trigger choice list).  So you go to your Event Registry and create a new event for the situation (notify.nonmember.update lets say).

Now you have a business rule capture the conditionality.
"When an incident is updated...." and in your script something like...

var membership = new GlideRecord('sys_user_grmember');
membership.addQuery('user',gs.getUser());
membership.addQuery('group',<sys_id of group in question>);  //(or current.assignment_group if you want scalability)
membership.query();

if (membership.next()){
  return;
} ele {
  gs.eventQueue('notify.nonmember.update',current,parm1,parm2) //you can send 2 parns with each eventQueue call
}

 

Now just build your notification to be fired by the notify.nonmember.update event.

Adam Stout
ServiceNow Employee
ServiceNow Employee

Instead of using the event queue, could this be done with Flow Designer?  That may allow for easier maintenance and expansion going forward.

Like a notification activity within a Flow Designer?  
Possibly, but much like Notification Activity in workflow, I hate notification definitions that don't actually exist in the notification table.

Eventqueueing allows you to keep your notification definition where it belongs (in notification definitions) and trigger it via script.

Hi Robert,

Great and helpful answer. Small code adjustment: the "else" is not needed here:

if (membership.next()){
  return;
} else {
  gs.eventQueue('notify.nonmember.update',current,parm1,parm2) //you can send 2 parns with each eventQueue call
}

// the else can be left out as the function has a return before that (not using if... else... makes code more readable and thus easier to maintain

if (membership.next()){
  return;
} 

gs.eventQueue('notify.nonmember.update',current,parm1,parm2) //you can send 2 parns with each eventQueue call

 

Just nitpicking, but imo reducing the use of if... else... makes code easier to maintain (especially in more complex scenarios).

Regards
Fabian