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

2 REPLIES 2

Andrew_TND
Mega Sage
Mega Sage

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');
        }
    },
});