- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 08:43 AM
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!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2018 08:56 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 10:38 AM
For this example, I will use an event called "oc_feedback.commented" (Be sure to change this to whatever custom event you are using for your notification). Based upon what you described, here is a Business Rule script that you can start with:
(function executeRule(current, previous /*null when async*/) {
var bcArray = []; //Array of found Business Contacts
var childTask = new GlideRecord('x_cur_oc_feedback_tasks');
childTask.addQuery('parent', current.sys_id);
childTask.query();
while(childTask.next()) {
if (childTask.business_contact != '') { //When there is a business contact defined:
bcArray.push(childTask.business_contact.toString()); //Add to Business Contacts Array
}
}
var arrayUtil = new global.ArrayUtil();
var rArray = arrayUtil.unique(bcArray); //Get the unique recipients and store in Recipient Array
gs.eventQueue('oc_feedback.commented', current, rArray); //Send notification
})(current, previous);
Let us know if this is successful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 10:41 AM
great thanks Christopher, I'll try this. Quick question, seeing the "global.ArrayUtil()", my app here is scoped, any conflicts with the "global"?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 10:47 AM
I used global in the instantiation of the Script Include because that script include is in the global scope. This Script Include is Accessible from all application scopes, so it should work so long as you call it from the scope it resides in.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 10:54 AM
my business rule in this scenario is in the scoped app, as the event...so the script include I believe will be called from the scoped app, not global.
so it won't work this way?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 10:58 AM
In order to use ArryUtil in a scoped application, you must prefix it with "global." This would include using it in Script Includes, business rules, workflow, etc.