Trying to pass email addresses from a list collector

Bidduam
Tera Guru

I have a catalog item that asks for a list of users, I'm using a list collector that is accessing the sys_user table.

 

What I want to do later in my flow is the send a notification to all users added to the list collector field on the catalog item

The field is called:

u_shared_staff

 

I am sending the notification via a fire event action in a flow. I've added the "u_shared_staff" data pill, but it doesn't dot walk to the email field, therefore it is adding to parm2 the sys id's of the users, not their email addresses and it therefore obviously doesn't actually send them the email.

 

Ideas?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Bidduam 

let the data pill pick sys_ids and it should work with sysIds as well of the users

If those sysIds have email address then email will be sent in email logs provided you are sending it correctly in event parm1 or parm2

share your flow screenshot

You can use flow variable and store all the user sysIds and then use this flow variable to set the recipients

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Ultimately I went down the path of adding a flow variable and completed a flow logic step of "Set flow variables" and added a data script to store the email addresses as a string.

 

Thanks

Hi Bidduam, 

I'm trying to solve the exact same problem as you. I created a flow variable and added the logic step "Set flow variables"; however, I'm stuck on the code to loop through the users and get their email addresses.

 

The field request_names is a list collector that references the sys_user table. Here's the code I have in the "Set flow variable" step that isn't working for me.  Any assistance you could provide would be greatly appreciated!

 

var names = fd_data._1__get_catalog_variables.service_request.request_names;
var nameArr = names.split(',');
var emailArr = [];
for (var i=0; i < nameArr.length; i++) {
    var sysuser = new GlideRecord('sys_user');
    sysuser.addQuery('sys_id', names[i]);
    sysuser.query();
    while (sysuser.next()) {
        emailArr.push(sysuser.email.toString());
    }
}
gs.info(emailArr);

 

@heatherdisn to be honest I can't remember exactly which flow I used this on, but I've had a look at the dates of when this question was asked and the flows I created around that time and am pretty confident that this is the right one lol

 

So I have a Flow variable that I called "Add user list" that is set as a string field

Bidduam_0-1747009550450.png

So for my flow I have:

  1. "List collector convert to array"
    The action input is my variable field (u_shared_staff), from the request item (retrieved in a "Get catalog variables" action earlier in the flow)
    Bidduam_1-1747010143055.png

     

  2. Then I have a logic step "For each" item in the previous flow step ("List collector convert to array") on the "variable" data pill.
    Bidduam_2-1747010247796.png

     

  3. Then a "Look Up record" on the sys_user table with the condition sys_id is variable_child0 (data pill) from the previous "For each" step
    Bidduam_3-1747010538422.png

     

  4. Then the "Set flow variables" logic step on the "Add user list" flow variable with the following script:
var add_list = fd_data.flow_var.add_user_list;

if (add_list == '')
    add_list = fd_data._15__look_up_record.record.email.toString();
else
    add_list += ', ' + fd_data._15__look_up_record.record.email.toString();

return add_list;​

*** Important to make sure that obviously you use your own flow variable name, but also the number of the correct look up flow step, eg: fd_data._15__look_up_record. ***

  • I then outside of the for each loop add a "Fire Event" action to add the flow variables to (in my case) the Parameter 2 field, that adds the email addresses to the email notification that is sent.
    Bidduam_4-1747011137745.png

     

     

I hope this helps 

 

 

 

@Bidduam Thank you so much!  That was very helpful.  I'll add these steps to my flow and see if it works. 

Hi @Bidduam ,

 

I'm trying to solve the exact same problem as you. I've created a flow variable, added the step "Set flow variables" and added code inside the "Set flow variable" step to retrieve the email addresses; however, the code I've written isn't working.  Any assistance or help you can provide would be greatly appreciated!

 

The request_names field is a list collector that references the sys_user table. Here's the code:

 

var names = fd_data._1__get_catalog_variables.service_request.request_names;
var nameArr = names.split(',');
var emailArr = [];
for (var i=0; i < names.length; i++) {
    var sysuser = new GlideRecord('sys_user');
    sysuser.addQuery('sys_id', names[i]);
    sysuser.query();
    while (sysuser.next()) {
        emailArr.push(sysuser.email.toString());
    }
}
gs.info(emailArr);