How to add reference field/value in 'Who will receive' tab in email notification

Nitin_NOW
Tera Guru

Hello Team

I have an issue related to email notification. We have a reference field in one of our catalog item. I'm trying to add this field in the 'Who will receive' tab in the notification,

find_real_file.png

but couldn't find the way. The point here is, upon resolution of the RITM, this notification should be triggered to the user's ( who is in the reference field ) manager.

find_real_file.png

Any idea on how to add this users ( scott hatch ) manager to be added in the 'users/group in field' list ?

Regards!

1 ACCEPTED SOLUTION

Hi Nitin,



If you noticed, I have declared a variable named 'recipient' in my last response. I'm passing that variable inside gs.eventQueue() function. The syntax of object.eventQueue() can be understood from the section 3.1 of this link GlideSystem - ServiceNow Wiki . If you are trying to send the email to the person who is selected in the reference field in the variable then you must define the variable as var recipient = current.variables.variable_name; If you are trying to send the email to the manager of the selected person then it would be like var recipient = current.variables.variable_name.manager; Reference field always passes the sys_id of any user, so you do not have to write recipient.name.


For your 2nd question, the answer will be YES. But you must remember the logic of call the same event must be different and same a single notification should be defined. Otherwise, whenever you are calling the same event from multiple business rules for multiple logic, the same notification will get triggered (considering the notification is selected as Event is fired with the same event).


Please try again now and let me know if you face any problem.



I hope this helps.Please mark correct/helpful based on impact


View solution in original post

11 REPLIES 11

Hi Nitin,



You should use the advanced checkbox in the notification activity and set the answer as the variable name of your terminated employee reference field. It should be:



answer = current.variables.variable_name; // variable_name = variable name of Terminated Employee



find_real_file.png



Let me know once it works



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


amlanpal
Kilo Sage

Hi Nitin,



Before providing the Solution I need to know from where the notification is getting triggered. From workflow or email (table) notification?
Considering both the cases the solution is provided as below:




From Workflow:


If the notification is getting triggered from the Notification activity in the associated workflow. Then you need to modify the Notification activity as of below:


find_real_file.png



From Email Notification:


If you are triggering the notification from the sc_req_item table itself, then you need to trigger the notification based on an event. You can define via one after update Business rule when the email will be triggered and also who will be set as parameter 1 and parameter 2 value. The Business Rule will look like below:


Table: Requested item (sc_req_item)


When: after


Update: Checked


Advance: Checked


Filter conditions: State changes to 'state_name' //You can pass the proper condition here as per your requirement when the email should be triggered


Script:


(function executeRule(current, previous /*null when async*/) {


  //Fetch the manager of the selected user from the variable


  var recipient = current.variables.variable_name.manager;


  //You need to pass the event name, which you are supposed to create (if not already) from Event registry for this Business rule


  //Pass the variable recipient as par1


  gs.eventQueue('event_name', current, recipient, recipient.name);


})(current, previous);



Now navigate to the particular notification via System notifications-->Emails-->Notifications-->Open the notification and modify the below things


1. Under Advanced view under 'When to send' tab select Event is fired in the 'Send when' field. And choose the Event name, which you have passed in the Business rule, in 'Event name' field.


2. Under 'Who will receive' tab Check the field 'Event parm 1 contains recipients'.



I hope this helps.Please mark correct/helpful based on impact


Hello Amlan



Very much thanks for your solution provided. I was configuring as above mentioned and stopped at one point as below


find_real_file.png



In the above code, what do you mean by 'pass the variable recipient as par1 ? I was trying to replace 'recipient.name' with the field value of reference field? But unable to get the output. Am I missing something here?



Apart from this, a single event can be used in multiple Business rules ?



Regards!


Hi Nitin,



If you noticed, I have declared a variable named 'recipient' in my last response. I'm passing that variable inside gs.eventQueue() function. The syntax of object.eventQueue() can be understood from the section 3.1 of this link GlideSystem - ServiceNow Wiki . If you are trying to send the email to the person who is selected in the reference field in the variable then you must define the variable as var recipient = current.variables.variable_name; If you are trying to send the email to the manager of the selected person then it would be like var recipient = current.variables.variable_name.manager; Reference field always passes the sys_id of any user, so you do not have to write recipient.name.


For your 2nd question, the answer will be YES. But you must remember the logic of call the same event must be different and same a single notification should be defined. Otherwise, whenever you are calling the same event from multiple business rules for multiple logic, the same notification will get triggered (considering the notification is selected as Event is fired with the same event).


Please try again now and let me know if you face any problem.



I hope this helps.Please mark correct/helpful based on impact


Hi Nitin,



If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.


If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View


.