We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

List collector have to get email ton populate by user name

Darlene York
Tera Contributor

I have a requirement to use a List collector and have the user that is selecteds email to populate by user name.

 

i can do it when it’s just a reference field and only one user can be selected.  But multiple users can be selected, that’s why I’m using a list collector. 

thank you in advance

 

6 REPLIES 6

VaniMadhuri
Tera Expert

Hi  @Darlene York 

A List Collector stores multiple selected users as comma-separated sys_ids, so you cannot dot-walk like a normal reference field. You need to send those selected sys_ids to the server and return the emails.
You can solve this with a Catalog Client Script + GlideAjax.


Script include code

var GetUserEmails = Class.create();
GetUserEmails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getEmails: function () {
        var userIds = this.getParameter('sysparm_user_ids');
        var emails = [];

        if (!userIds)
            return '';
        var userGR = new GlideRecord('sys_user');
        userGR.addQuery('sys_id', 'IN', userIds);
        userGR.query();
        while (userGR.next()) {
            if (userGR.email) {
                emails.push(userGR.email.toString());
            }
        }
        return emails.join(', ');
    },
    type: 'GetUserEmails'
});

 

VaniMadhuri_2-1778030827455.png

 

 

Catalog Client Script for AWS Account Request and Variable name is “list of users”

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || !newValue) {
        g_form.setValue('user_emails', '');
        return;
    }

    var ga = new GlideAjax('GetUserEmails');
    ga.addParam('sysparm_name', 'getEmails');
    ga.addParam('sysparm_user_ids', newValue);

    ga.getXMLAnswer(function(answer) {
        g_form.setValue('user_emails', answer);
    });


   //Type appropriate comment here, and begin script below
   
}

VaniMadhuri_1-1778030801819.png

While tests in AWS Account Request 

  • User selects multiple users in List Collector
  • Script runs on change
  • Sends selected users to Script Include
  • Fetches emails
  • Then it automatically populates email field

VaniMadhuri_0-1778030764059.png

 

 

 

If you found this useful, feel free to mark it as Helpful and accept it as the solution.
Regards,
VaniMadhuri

Ankur Bawiskar
Tera Patron

@Darlene York 

Sorry you will have list collector and when user selects multiple users what should happen?

 

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

@Darlene York 

any update to this?

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

Tanushree Maiti
Tera Patron

Hi @Darlene York ,

I dont think your requirement is feasible.

 

You can do one thing. 

To display user emails from a List Collector, use an onChange Client Script paired with GlideAjax to fetch email addresses for selected users and populate them in a Multi-Line Text variable. The List Collector displays user names (from the sys_user table), while the script converts these into email addresses.

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti