best way to set recipients on a notification?

patricklatella
Mega Sage

Hi gang,

I want to put together a notification that will send to users who are entered into a reference field on child tasks of a parent record.

Here's the scenario:

I have a custom table [x_cur_oc_feedback_oc_feedback] that has a [comments] field; this table is extended from task.   Records in this table can have related child tasks.   The child tasks have a custom field [business_contact] for assigning the task.

If the [comments] section on the parent record changes, I want a notification to be sent to the users entered in the [business_contact] field on the child tasks associated with the parent record (if there are any).

What's the best way to do this?

Should I write an email script to do a GlideRecord query to get the names in the [business_contact] field on the child tasks?   How do I then set that list of names as the recipient of the email?

Or should I create an event that triggers a script action that queries and passes the names for the recipients of the email?

not sure which way to go...thanks!

1 ACCEPTED SOLUTION

Based upon the recent suggestions,here is the script for the Business Rule:


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


// Query for existing child tasks and gather list of any actionees


      var gr = new GlideRecord('x_cur_oc_feedback_tasks');


      gr.addQuery('parent',current.sys_id);


      gr.query();


      var bcArray = [];//array of business contacts from child tasks


      while(gr.next()){


              if (gr.business_contact !=''){


                      if (bcArray.toString().indexOf(gr.business_contact) == -1){


                      bcArray.push(gr.business_contact.toString());


                      }


              }


      }


      gs.eventQueue('x_cur_oc_feedback.comments.added.notify',current,bcArray,'','');


})(current, previous);


View solution in original post

39 REPLIES 39

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

I know you are already down a path, but another option would be an after update business rule on the parent record that copies down the comment to the child tasks.   Then setup a notification for the child tasks to send an email to the business contact on a comment update.   Splitting hairs here but its another way.   With my option an email will be sent for each task to the business contact with a single recipient versus the other solution where 1 email with multiple recipients.   Not sure if there is a preference or security around the recipient list but I thought I would suggest this.


Hi Michael,


thanks for the additional solution idea...I had not thought of that.   However in this case I think we would not want to do that because I already have a notification on the child task table to send to the business_contact when the comments section on the child task record changes...which in my scenario would be done by a specific team member.   So having that email send in this case would not be accurate.   thanks though!


patricklatella
Mega Sage

I'm getting this regarding the event...what does it mean my event is not defined?



find_real_file.png


here's the event record



find_real_file.png


patricklatella
Mega Sage

ahh, ok.   that makes sense.   There is the possibility that multiple child tasks could have the same business contact and we would not want multiple emails getting sent.   So this ensures unique values?


Yes sir.   Its performing the same "unique" function that ArrayUtil provides with one less "hop".   ArrayUtil is great but I find it unnecessary and causes a little more overhead in this scenario.