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

Harsh Vardhan
Giga Patron

Writing glide record in client side scripting is not a good practice. 

I would suggest use glide ajax and do the glide record part inside client callable script include. 

 

Sample Code:

 

Script Include:

 

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

	helloWorld: function(){

		var et = this.getParameter('sysparm_user_name');
		var res = et.split(',');
		var abc = [];
		for(var i=0;i<res.length;i++){
			var gr = new GlideRecord('sys_user');
			gr.get('sys_id',res[i]);
			abc.push(gr.getValue('email'));
		}
		return abc.join(",");

	},

	type: 'HelloWorld'
});

 

Screenshot:

 

find_real_file.png

 

 

Catalog Client script:

 

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	//Type appropriate comment here, and begin script below
	var ga = new GlideAjax('HelloWorld');
	ga.addParam('sysparm_name', 'helloWorld');
	ga.addParam('sysparm_user_name', g_form.getValue('test').toString());
	ga.getXML(HelloWorldParse);
	function HelloWorldParse(response) {
		var answer = response.responseXML.documentElement.getAttribute("answer");
		
		g_form.setValue('test1',answer); 
	}

}

 

Screenshot:

 

find_real_file.png

 

 

Result:

 

find_real_file.png

 

 

Note: set the variable name correctly in client script, i test and working perfectly. 

 

If my answer helped you, kindly mark it as correct and helpful.

Hi @Harshvardhan - when I add the user's name, the email does not populate.

find_real_file.pngfind_real_file.png

i tested it and its working perfectly at my end. can you please add alert() inside client script and see what are you getting there ?

 

find_real_file.png

Hi Mairvette,

Can you try my code as mentioned in my last reply?

 

Thanks,

Mohit

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)