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

OK, I think I got that...but where do I do the GlideRecord query...in the business rule?



and will that gr object be able to pass multiple recipients?


If you have not done so already, you will need to have a custom event for your notification. Make sure that it resides on the table where the parent record is [x_cur_oc_feedback_oc_feedback]. Make sure that your notification also is on this table and that it uses the event you created. There is a Event parm 1 contains recipient or Event parm 2 contains recipient checkbox on the notification, make sure that one of these is checked.



The business rule needs to run after update so that it can grab the recipients from the child records. Depending upon how your parent/child relationship is set up will determine how to query the child tasks for the recipients. Is your child task on the same table as the parent? What field is used to connect the child to the parent?



Please let us know how your parent to child relationships are defined so we can narrow our solution accordingly.


patricklatella
Mega Sage

Hi Christopher,


thanks for clarifying.  



Regarding the parent/child relationship...the child tasks are on a separate table (also extended from task), [x_cur_oc_feedback_tasks], which is configured as a related list on the parent table [x_cur_oc_feedback_oc_feedback]



Quick question, would it be better for this Business Rule to be an "async" instead of "after", or is this not a case for that?


In our scenerio it is best that we run the business rule after the record has been saved. This way it will do any calculations, updates etc. before the notification is actually sent.



Do you know what field is used to tie the Child Tasks [x_cur_oc_feedback_tasks] table to the parent [x_cur_oc_feedback_oc_feedback] table? For example, within the Catalog Task [sc_task] table, there is a reference field called Request item [request_item] that points to the Requested Item [sc_req_item] record. This will be helpful in our query in that we want to find only those child records that are related to the parent record.



Also, what kind of field is the business_contact field? Is it a reference field? Is it a list field? Does it point to the User [sys_user] table? Knowing those will help us in determining how to get the list of recipients.


patricklatella
Mega Sage

ok, thanks, will set as an "after" business" rule



the field that ties the child table to the parent table is "parent"



and business_contact field is a reference to the sys_user table