Multiple values store in one variable

Debarpita Basak
Giga Contributor

Hi All,

How i can store multiple values in one varible and join with comma , by current sys_id  i am getting two sysid  i want store two sys_id in one variable ?  

in ui action var sys_id = current.sys_id;// getting two sys_id want to join in one variable
var arr = [];

var SYSID = arr.join(',');
gs.addInfoMessage(SYSID);

1 ACCEPTED SOLUTION

@Debarpita Basak 

I am already responding on this thread.

So if you think I answered your original question of setting the number field with the list of RITMs selected then mark my response as correct and close this question.

Regards
Ankur

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

View solution in original post

25 REPLIES 25

Hi Ankur,

attaching two screenshot array is coming blank. How will i save the ritm number in scratchpad variable after selecting ritm because i have to use reference field

@Debarpita Basak 

not sure if 2 level dot walking is allowed in client side GlideRecord

Can you try this

I know this is not best practice to use GlideRecord in client script and that too 2 times

But just want to confirm

Once confirmed you can use GlideAjax with Synchronous call and call script include and get all the requested for

function sendCustomEmail() {

	var sysIds = g_list.getChecked().toString();
	var requested_forArray = [];

	for(var i=0;i<sysIds.length;i++){
		var gr = new GlideRecord("sc_req_item");
		if(gr.get(sysIds[i].toString())){

			var req = new GlideRecord('sc_request');
			req.get(gr.request);
			if(req.requested_for){
				requested_forArray.push(req.requested_for.toString());
			}
		}
	}
	alert('array->'+ requested_forArray);

	var url = '/sc_task.do?sys_id=-1&sysparm_query=u_number=' + sysIds + '^u_to_whom=' + requested_forArray.toString();
	top.location.href = url;
}

Regards
Ankur

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

@Debarpita Basak 

Or as an alternative try this

Display business rule on sc_task

Script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var ritms = current.u_number.toString();
	var arr = [];
	var gr = new GlideRecord("sc_req_item");
	gr.addQuery("sys_id", "IN", ritms);
	gr.query();
	while(gr.next()) {
		arr.push(gr.request.requested_for.toString());
	}
	current.u_to_whom = arr.toString();

})(current, previous);

From UI Action only set the u_number

sendCustomEmail();

function sendCustomEmail() {
	var sysIds = g_list.getChecked().toString();
	var url = '/sc_task.do?sys_id=-1&sysparm_query=u_number=' + sysIds;
	top.location.href = url;
}

Regards
Ankur

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

Hi ankur ,

My seniors has guided me to to store the sysid of selected ritm in g_scratchpad

at present the field is reference in my project dev i have use that scratchpad

https://community.servicenow.com/community?id=community_question&sys_id=b5835242db0c7c106064eeb5ca96192f

Kindly guide me

@Debarpita Basak 

I already mentioned the another approach i.e. using Display BR and the UI Action

Did you try that?

Also you can use this if you want scratchpad variable

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var ritms = current.u_number.toString();
	var arr = [];
	var gr = new GlideRecord("sc_req_item");
	gr.addQuery("sys_id", "IN", ritms);
	gr.query();
	while(gr.next()) {
		arr.push(gr.request.requested_for.toString());
	}
	g_scratchpad.users = arr.toString();

})(current, previous);

Then use onLoad client script to set the value

function onLoad(){
	if(g_scratchpad.users != ''){
		g_form.setValue('u_to_whom', g_scratchpad.users.toString());
	}
}

Regards
Ankur

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