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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

25 REPLIES 25

enhance as this

I assume u_type is also referring to sc_req_item table

    var url = '/sc_task.do?sys_id=-1&sysparm_query=u_number=' + sysIds + '^u_type=' + sysIds;

So final script

sendCustomEmail();

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

Regards
Ankur

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

Hi Ankur ,

 

I have tried the code but it is not working like exactly what i told in screenshot1 you can see that in To it attaching the ritm sys_id . my requirement is in To field it will selected ritm.requested_for and in number it will store ritm number working as expected 

script modified:

function sendCustomEmail() {
var sysIds = g_list.getChecked().toString();
var requested_for = [];
for(i=0;i<sysIds.length;i++){
var gr = new GlideRecord("sc_req_item");
if(gr.get(sysIds[i].toString())){
requested_for.push(gr.request.requested_for.toString());
}
//gs.addInfoMessage("EmailClient " + requested_for);
}

var url = '/sc_task.do?sys_id=-1&sysparm_query=u_number=' + sysIds + '^u_to_whom=' + requested_for;
top.location.href = url;

}

@Debarpita Basak 

Try to update as this

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())){
			if(gr.request.requested_for){
				requested_forArray.push(gr.request.requested_for.toString());
			}
		}
	}
	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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

After saving the coding whenever i am selecting and clicking it taking long time to open the form. why it is so? 

after loading a new form to is empty. screenshot attached

Because you are doing GlideRecord in client side.

Can you share what came in the array?

Is the field name u_to_whom correct

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())){
            if(gr.request.requested_for){
                requested_forArray.push(gr.request.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
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader