How to push multiple value in Variable

Pallavi Shinde2
Tera Contributor

I have one variable having type "List collector" with list table sys_user_group, right now i am able to push single value in variable, but i want to push multiple in the variable. The issue is when I select 2 values from catalog item it is taking single value only. Please suggest me below is script i am using to push the values

PallaviShinde2_1-1717051952257.png

Regards,

Pallavi 

 

 

4 REPLIES 4

Voona Rohila
Kilo Patron
Kilo Patron

HI @Pallavi Shinde2 

 

Can you show the gliderecord part of the above code?


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Community Alums
Not applicable

Hi @Pallavi Shinde2 ,

I tried your code in my PDI and it works for me. Please refer below script 

var incgr = new GlideRecord('incident');
incgr.addQuery('sys_id', '47064b68a9fe19810186793eefffc9b7');
incgr.query();
if(incgr.next()){
	var user = [];
	var userGr = new GlideRecord('sys_user');
	userGr.addEncodedQuery('nameSTARTSWITHuser');
	userGr.query();
	while(userGr.next()){
		user.push(userGr.sys_id.toString());
	}
	gs.print("User = " + user.join(","));
	incgr.watch_list = user.join(",");
	incgr.update();
}

 

Result 

SarthakKashyap_0-1717052698883.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

dgarad
Giga Sage

Hi @Pallavi Shinde2 

 change the return code

 

return access.join(',')

 

  

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Hayo Lubbers
Kilo Sage

Hi @Pallavi Shinde2 ,

 

You join with a \n instead of a comma. List Collectors have a comma seperated list of values.

 

You can use the toString() method or keep the join() without parameters.