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

How to fetch values from list collector in client script

Snehal13
Kilo Sage

How to fetch values from list collector in client script

1 ACCEPTED SOLUTION

RAMANA MURTHY G
Mega Sage

@Snehal13 

ListCollector_Demo.png

 

I have tried with List Collector in Catalog Client Script to fetch the email ID of users and shows in the text field below

Here is the code (you can change it according to your requirements)

 

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   var traineesNames = g_form.getValue('select_trainee');  // 'select_trainee' is the backend name of the List Collector
	var trainees = traineesNames.split(',');
	var traineeEmails = [];
	
	for(var i=0;i<trainees.length;i++){
		var gr = new GlideRecord('sys_user');
		gr.addQuery('sys_id',trainees[i]);
		gr.query();
		while(gr.next()){
			traineeEmails.push(gr.email);
		}
	}
	g_form.setValue('trainees_email_id',traineeEmails);  // 'trainees_email_id' is the back end name of the text field
   
}

 

 

Please give me correct and helpful, if my answer helps to your requirement.

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Snehal13 

you didn't share what you tried so far and what's your requirement

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

Niamul Arifin
Tera Expert

This above solution is for global scope. Also, calling server side script from client side not preferred.

Anyone has worked on this in a scoped app environment? I have similar use case as this one mentioned above however, i am looking to see anyone implemented Script Include and catalog client script in scoped app for this solution.

Snehal13
Kilo Sage

Solution has been marked and no further follow up or help is required. Thank you.