The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Populate all the users selected in "requested for" in requested for email id variable in servicenow

tulasi8
Tera Contributor

Hi Community,

 

Here my requirement is , for a catalog item "requested for" should allow multiple selections, if they select 4 users all those 4 users email id should get populate in "requested for email" . I have written script include and on change client script on "requested for" but it's not working. Can anyone please help to achive this requirement . @Ankur Bawiskar 

 

Thanks,

Prasanna

9 REPLIES 9

@Ankur Bawiskarbut workflow will run once the request is submitted only . But here while they are entering the details in the portal, then only it should populate in "requested for email " variable in the form itself 

@tulasi8 

yes that link has logic for onChange catalog client script from Asif

Use that script

AnkurBawiskar_0-1758621524271.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

@Ankur Bawiskar it's not working 
script include name : FetchAllEmailIds
client callable :checked 
script :

var FetchAllEmailIds = Class.create();
FetchAllEmailIds.prototype = Object.extendsObject(AbstractAjaxProcessor, {
   
    get_email: function() {
        var userArr = this.getParameter('sysparm_users').toString().split(',');
        var emailArr = [];

        for (var i = 0; i < userArr.length; i++) {
            var grUser = new GlideRecord('sys_user');
            if (grUser.get(userArr[i])) {
                emailArr.push(grUser.getValue('email'));
            }
        }

        return emailArr.join(', ');
    },

    type: 'FetchAllEmailIds'
});
On change client script 
on change : requested_for
script : 
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        g_form.clearValue('requested_for_email');
        return;
    }

    var ga = new GlideAjax('FetchAllEmailIds'); // Script Include name
    ga.addParam('sysparm_name', 'getSelectedEmails'); // Method name in Script Include
    ga.addParam('sysparm_selected_users', newValue); // Comma-separated sys_ids
    ga.getXMLAnswer(function(answer) {
        g_form.setValue('requested_for_email', answer); // Set the email field
    });
}





tulasi8
Tera Contributor

@tulasi8 

so what debugging did you do

1) is script include client callable

2) what came in alert as response in Ajax?

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