Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Add multiple email addresses to List Collector on Service Portal/Catalog

Mairvette Tuck1
Mega Contributor

Hello.

Within a catalog item, we have two fields. One is for the user's name the other for their email address.

I've used the table 'sys_user' for both fields. When the user's name is populated, I have it automatically adding their email address to the specific email field, both with 'List Collector' as their variable type.

Issue I am having, is if multiple users are added to the User field, no email address (even previously displayed for the first user) will be displayed. How do I get each additional email address to be displayed in the List Collector / email field?

find_real_file.pngfind_real_file.png

30 REPLIES 30

oops give it var instead of int. Sorry my mistake.

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Okay. updated that. Get this now:

find_real_file.png

Sorry My bad, I was not using any editor while writing the script so it is throwing errors which is not in code . But the comment,

you can use the fresh script as shown below

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var ids = g_form.getValue('users_add').toString().split(','); // to get the comma separated ids.

    var emailids = '';

    var user;

    for (var i = 0; i < ids.length; i++)

    {

        user = new GlideRecord('sys_user');

        user.query('sys_id', ids[i]);

        user.query(myCallbackFunction);

    }



    function myCallbackFunction(user) {

        if (user.next())

        {

            if (emailids =='')

            {

                emailids = user.email; // for first record

            } else {

                emailds = emailids + ',' + user.email; //if multiple records

            }

        }

    }

    g_form.setValue('email_address_add', emailds);

}
Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

getting this error now:

find_real_file.png

can you try running this in native UI first. I want to know if this code is working or not. If yes then we can modify it for portal as well.

Please confirm

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)