Sending a dynamic email based on a user field

ServiceNowSteve
Giga Guru

Good Afternoon All,

I have a custom list on my user record that holds information, for this explanation let's just say it's letters A, B and C.

How can I send an email out to all users in the user table that have a letter A in their list and not to ones that don't? Mind you this is not a group or role in this list so that wouldn't be an option.

1 ACCEPTED SOLUTION

Patrick Schult2
Giga Guru

Your question really is just "When I go to send an email, how can I add a bunch of recipients using logic that I decide?". The answer is...mail scripts! You can use a mail script in your notification that queries your user table, then adds recipients to that outbound email. In your case, your email script is going to do a lookup to the User table for users with letter A (or whatever), and add each of them to the email using the email.addAddress method.



Docs on email scripting: Scripting for email notifications


Examples of email scripts, including an example that adds addresses to the outbound email: Example scripting for email notifications


View solution in original post

3 REPLIES 3

sachin_namjoshi
Kilo Patron
Kilo Patron

You can create business rule on user table to send notification to users whose name contains A.


You need to find out trigger for business rule.



Please use below script   to query glide list field and then add script to cpare user name with array[i]


values



var list = current.watch_list.getDisplayValue();


  var array = list.split(",");


  for (var i=0; i < array.length; i++) {


    gs.print("Display value is: " + array[i]);


  }



Regards,


Sachin



Patrick Schult2
Giga Guru

Your question really is just "When I go to send an email, how can I add a bunch of recipients using logic that I decide?". The answer is...mail scripts! You can use a mail script in your notification that queries your user table, then adds recipients to that outbound email. In your case, your email script is going to do a lookup to the User table for users with letter A (or whatever), and add each of them to the email using the email.addAddress method.



Docs on email scripting: Scripting for email notifications


Examples of email scripts, including an example that adds addresses to the outbound email: Example scripting for email notifications


I haven't get gotten this to work but I think this is the right path. Thanks for the insight.