How to write an advanced condition for "Who will receive" user, not current user?

0rland0h
Kilo Explorer

Trying to find out how to write an advanced condition that will check for the user that is under, 'Who will receive" and not the current user that is triggering an incident. I am trying to write a blackout period for the user of Who will receive section, to NOT receive an email from a set period of time. I have currently written a script that will trigger based on roles, which is what we would probably end up doing.

This is what I currently have:

var currentUser = gs.getUser();

if(currentUser.hasRole('enter any role here.')){ //you can insert admin role or itil role and it runs as expected

        var n = new Date().getHours();

      gs.log('This is what n is going to be');

        if(n >= 14 && n <= 15){ //based on a 24 hour clock

              gs.log('This is true!'); //logging for the purposes of tracking the variables.

                answer = true;

      }

        else{

              gs.log('This is not running as intended');

                answer = false;

        }

}

else

{

gs.log("This didn't run period!!!!! ")

answer = false;

}

What I need to be able to include in this, is the "Who will receive" user. I do not need the user that is triggering the event to not be able to trigger this condition. We have other notifications that will trigger that rule.

Any suggestions? Any clarifications can be answered as well.

Thank you!

7 REPLIES 7

LaurentChicoine
Tera Guru

For the first part, if you don't want the current user to receive the notification, you can simply uncheck the Send to event creator check box (you have to be in advanced view to see this checkbox). But I'm not sure this is what you are looking for as I had difficulty understanding your question.



If you want to add condition based on the role of the Who will receive user (which is what I seem to understand), you could go get these user using current.field_name_with_user for user based on field or running a GlideRecord query for any other users. If the who will receive is in event parameter you could also access that using event.parm1 or event.parm2.



If, I'm off the track, please give me more details about what you are trying to achieve.


You are probably on the right track with what I am trying to figure out, but woudl this need to be written in the Notification scripting area, or would this be written in some other place? Like a GlideAjax style code?


This would need to be writen inside the advanced condition script inside the advanced view of the notification form. However this condition will get evaluated for the whole notification.



So if you have user with different roles inside two different field you would propably need one notification for "Who will receive" with a single field and another notification for the second field, etc.



Otherwise you could go the business rule way and build a script that triggers notification event containing the "Who will receive" inside the event parameters. The business rule way usually allows more complex scripting situation for notifications.


Deepak Ingale1
Mega Sage

Scripting for Email Notifications - ServiceNow Wiki


You might be interested in above link.