The CreatorCon Call for Content is officially open! Get started here.

Populate first selected user Email id from Multi-Select "Requested For" Field in Catalog Item

tulasi8
Tera Contributor

Hi Community,

 

I’m working on a catalog item where the "Requested For" field needs to support multiple selections, so I’ve configured it using a List Collector.

Additionally, I’ve created a second variable to capture the email address of the selected user(s. This variable is of multi-line text type, and I attempted to autopopulate it using a dependent question and dot-walk path from the "Requested For" field. However, this approach does not work with List Collector variables.

To test the functionality, I temporarily changed the "Requested For" field to a Reference type, and the email autopopulation worked as expected. However, this does not meet the requirement, as I need to allow multiple user selections and populate only the first selected user's email ID in the second variable.

Could you please advise on how to achieve this functionality? Any guidance or recommended approach would be greatly appreciated. @Ankur Bawiskar 

 

Regards,

Tulasi

6 REPLIES 6

Community Alums
Not applicable

Hey @tulasi8 

 

So I’ve got this right your form has a requested for list collector field which when loaded needs to auto populate the current users email address but also be open for other emails? At a high level is this correct? If so sounds like you need an onLoad catalog Client Script to achieve this. Let me know if my understanding right and I can whip something up. 

Thanks

Andrew

Brad Bowman
Kilo Patron
Kilo Patron

Use an onChange Catalog Client Script when Requested for changes.  If the email variable is blank, the script will call a Script Include via GlideAjax to fetch the email address for the sys_id / newValue you pass it - so something like this, depending on your variable names...

if (g_form.getValue('v_email') == '') {
    var ga = new GlideAjax('GetUserInfo');  
    ga.addParam('sysparm_name','getEmail');
    ga.addParam('sysparm_user', newValue);
    ga.getXMLAnswer(function(ans){
        g_form.setValue('v_email', ans);
    });
}
var GetUserInfo = Class.create();
GetUserInfo.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    getEmail: function() {
        var id = this.getParameter('sysparm_user');
        var gr = new GlideRecord('sys_user'); 
        if (gr.get(id)) {
            return gr.getValue('email');
        }
    },
});

 

Ankur Bawiskar
Tera Patron
Tera Patron

@tulasi8 

that's correct, auto-populate only works with reference and won't work with list collector

Why not use onChange + GlideAjax and populate the emails comma separated?

this link has solution from Asif

Populate Email Addresses of users selected in List Collector variable to Multi Line Text Variable 

AnkurBawiskar_0-1759294156344.png

 

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

@tulasi8 

Hope you are doing good.

Did my reply answer your question?

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