- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2017 09:46 AM
I think I have most of the components to have this work but i'm missing something.
I have workflow triggering an event to fire an notification. The event contains a parameter script to get a list of email addresses from a list of users from a list collector. I can generate the array no problem.
Create Event activity:
(function() {
var arrayEmail = [];
var gr = new GlideRecord('sc_req_item');
gr.addQuery('number', current.sys_id);
gr.query();
if (gr.next()) {
var arrayUtil = new ArrayUtil();
var list = gr.variables.proj_employee_remove_list.toString();
var arrayList = list.split('.');
l = arrayList.length;
for (var i=0; i<=l; i++) {
var ue = new GlideRecord('sys_user');
ue.addQuery('sys_id', 'IN', arrayList[i]);
ue.query();
while (ue.next()) {
arrayEmail += (ue.email + ',');
}}
return "arrayEmail";
}
}());
The problem is passing the email addresses to the notification. I have the parameter 1 selected in the notification. The event fires but returns the RITM that's associated with workflow. What else am i missing or doing incorrectly?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2017 01:41 PM
Looks like I had an error with the first part of the query. It should have been a 'sys_id', current.sys_id
Second, the parameter needs to pass the sys_id of the users so the second half of the script was wholly unnecessary.
I'm not sure if the toString at the end is necessary since it's already in a string format but it didn't hurt.
Thanks for the suggestions!
(function() {
var arrayEmail = [];
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id', current.sys_id);
gr.query();
if (gr.next()) {
var arrayUtil = new ArrayUtil();
var list = gr.insertvariablename.toString();
var arrayList = list.split(',');
l = arrayList.length;
return arrayList.toString();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2017 09:56 AM
I corrected line 24. Also line 12, I think you should split based on comma instead of '.'
- (function() {
- var arrayEmail = [];
- var gr = new GlideRecord('sc_req_item');
- gr.addQuery('number', current.sys_id);
- gr.query();
- if (gr.next()) {
- var arrayUtil = new ArrayUtil();
- var list = gr.variables.proj_employee_remove_list.toString();
- var arrayList = list.split('.');
- l = arrayList.length;
- for (var i=0; i<=l; i++) {
- var ue = new GlideRecord('sys_user');
- ue.addQuery('sys_id', 'IN', arrayList[i]);
- ue.query();
- while (ue.next()) {
- arrayEmail += (ue.email + ',');
- }}
- return arrayEmail;
- }
- }());
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2017 09:59 AM
Wouldn't that script always return the string, "arrayEmail"?
I would've imagined the code to look something like below.
(function() {
var arrayEmail = [];
var gr = new GlideRecord('sc_req_item');
gr.addQuery('number', current.sys_id);
gr.query();
if (gr.next()) {
var arrayUtil = new ArrayUtil();
var list = gr.variables.proj_employee_remove_list.toString();
var arrayList = list.split('.');
l = arrayList.length;
for (var i = 0; i <= l; i++) {
var ue = new GlideRecord('sys_user');
ue.addQuery('sys_id', 'IN', arrayList[i]);
ue.query();
while (ue.next()) {
arrayEmail.push(ue.getValue('email'));
}
}
return arrayEmail.toString();
}
}());
Also, what does your event call look like?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2017 10:10 AM
I tried both options. Still only shows the request item number in the parm1 field in the event queue. I would expect the list of email addresses to be displayed instead.
I originally had returned the arrayEmail variable as is but thought quotes would work as the docs explained it.
The event logs look like this

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2017 10:18 AM
What does your gs.eventQueue() call look like? Are you sure you're aligning the arguments properly?
For example, parm1 in the call below is 'current.marketing_event'.
gs.eventQueue('x_snc_marketing_ev.attendee.added', current, current.marketing_event, current.email);