Notification script

Walter Toney
Tera Expert

I have a requirement to send a notification to a person/Group if they meet the conditions. i don't want to have 15 different notifications so im look for assistance in a script to make this all neater

 

 i have a 2 variable as (Job) and (Task) based on that selection I have to send a notification to the User/Member associated with those selection

 

example

 

if the variables are (job- Principle) and (Task - Athletics) - send Notfication to Mark.Davis@email.com

if the variables are (job- Teacher) and (Task - Mathematics) - send Notfication to Sarah.Jenkins@email.com

 

and so on. but the 2 variables are the constant

 

does anyone have an example 

 

 

1 ACCEPTED SOLUTION

Chaitanya naram
Kilo Sage

Hi @Walter Toney 

 

You can pass the those two values in event parameter's if those are not available on the table record on which you created notification. And then create a new email script, where you can put validation like below

consider parm1 contains job, parm2 contains task. then script would be
if(event.parm1=="Principle" && event.parm2=="Athletics") email.addAddress('to','Mark.Davis@email.com');

else email.addAddress('to','Sarah.Jenkins@email.com');

If your notification is on RITM and both variables available on the question variables section, you can access it using current.<variable_name> in email script without parameters.

Another best approach in long run is using decision table. Going on, you may receive multiple combinations for JOB and TASK and different users need to receive an email for each combination.

So, what you can do over here is create a decision table with 2 inputs TASK and JOB and output variable as user Reference to user table/ User email reference to email in user table/ email which is a string property.

and then you can call the decision table by passing the parameters and get the response with out writing if else for every combination. This helps in maintaining the logic in better way and reduces the script changes every time.

https://docs.servicenow.com/bundle/vancouver-application-development/page/administer/decision-table/...

 

 

Thanks & Regards | Chiranjeevi Chaitanya Naram
Kindly mark the answer Correct and Helpful if it helps to resolve your issue.

View solution in original post

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Walter Toney 

 

How many value these 2 variable contains based on that , you can create condition in flow designer and hardcore the email address in that way.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Maik Skoddow
Tera Patron
Tera Patron

Hi @Walter Toney 

Basically you only need one notification (record) which can be triggered by an event. And one of the two parameters you can use for carrying information (parm1 or parm2) of the recipient(s). In in your notification you can configure that ServiceNow should take the recipient information from parm1 or parm2.

Now you only need a place where the events are triggered and filled accordingly. Here I can recommend the Flow Designer which provides a Low/No-Code environment to model the business process in a visual way.

Maik

Chaitanya naram
Kilo Sage

Hi @Walter Toney 

 

You can pass the those two values in event parameter's if those are not available on the table record on which you created notification. And then create a new email script, where you can put validation like below

consider parm1 contains job, parm2 contains task. then script would be
if(event.parm1=="Principle" && event.parm2=="Athletics") email.addAddress('to','Mark.Davis@email.com');

else email.addAddress('to','Sarah.Jenkins@email.com');

If your notification is on RITM and both variables available on the question variables section, you can access it using current.<variable_name> in email script without parameters.

Another best approach in long run is using decision table. Going on, you may receive multiple combinations for JOB and TASK and different users need to receive an email for each combination.

So, what you can do over here is create a decision table with 2 inputs TASK and JOB and output variable as user Reference to user table/ User email reference to email in user table/ email which is a string property.

and then you can call the decision table by passing the parameters and get the response with out writing if else for every combination. This helps in maintaining the logic in better way and reduces the script changes every time.

https://docs.servicenow.com/bundle/vancouver-application-development/page/administer/decision-table/...

 

 

Thanks & Regards | Chiranjeevi Chaitanya Naram
Kindly mark the answer Correct and Helpful if it helps to resolve your issue.