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

patricklatella
Mega Sage

business rule is in my scoped app [x_cur_oc_feedback]


I was able to reproduce that error in my instance with a scoped application when the event name in the BR wasn't correct.   Something is up between the name of the event in your gs.eventQueue() function and the name of the event in your registry.   Maybe try changing the event name to comments_added and update your script and see if it works.   You may also need to reselect the event in your notification as well.


According to the Product Documentation for Scoped eventQueue:


GlideSystem - Scoped



It appears that there is a need for a parm3 to define the name of the queue. What we can do is change the syntax to include parm2 and parm3 (which are both blank):


      gs.eventQueue('x_cur_oc_feedback.comments.added', current, bcArray, '', ''); //Send notification



Hopefully this will send within your scoped app without the error.


patricklatella
Mega Sage

hi guys,


it's working!   Those last couple tweaks did the trick...I deleted the event I had created and started fresh.   The new event name is below in the script (maybe it needed 3 words??).   I also added the 2 empty Parms.



Here's my final script.   If one of you wants to reply with this final script solution in your reply I'll mark you answer correct.   thanks guys!



(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);


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);