Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

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

Ankur Bawiskar
Tera Patron

@Debarpita Basak 

Can you share your complete script so that it would be easier

Regards
Ankur

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

hi ankur, 

Actually i am trying to create a record task for multiple ritm that want to store multiple sys_id into task field , field type :list, thats why wants to store multiple sys_id in one varaible .

i have add one option"Send custom email" in ritm list page in available in selected rows like delete if i select multiple rom in ritm list it will open one task record and want to store multiple ritm sysid in that form

ui action script "Send custom mail"

script :

sendCustomEmail();
function sendCustomEmail() {

// var sys_id = current.sys_id;
// current.number= sys_id;

var arr = [];

arr.push(current.sys_id.toString());

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

gs.addInfoMessage(SYSID);


var url = 'sc_task.do';
action.setRedirectURL(url);
action.setReturnURL(current);



}

Hi,

Still not clear.

Can you please frame the question with correct details and screenshots as well.

Regards
Ankur

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

Hi Ankur,

In list choice i have added option like delete ui action , if i select multiple ritm then click new ui action(screenshot 1) it is opening a form ,sc_task new form(screenshot 2) , in that new form i have a field number - field type of number (screenshot 3)is list it will store all the sysid in that particular field number . Kindly check the attachment and guide me . 

 

In ui action script if i am using current.sysid i am getting the separtely as u can see i screenshot 2 by add gsaddinfomessage it is diplaying on the top of screenshot2. for your understanding copy and pasting the code i am using in ui action

script :

 

sendCustomEmail();

function sendCustomEmail() {

var sys_id = current.sys_id;

gs.addInfoMessage("deb56 " + sys_id);

'Ankur' i have also tried with this correct the pattern if it wrong or i have to add anything 
// 
// tblName = g_list.getTableName();


// selSysIds = g_list.getChecked();


// sysIdList = selSysIds.join(',');


// numSel = sysIdList.length;
// gs.addInfoMessage("deb56 " + numSel );

// gs.addInfoMessage("deb62 " + sysIdList);

var url = 'sc_task.do';
action.setRedirectURL(url);
action.setReturnURL(current);



}

@Debarpita Basak 

So whatever RITMs you select should be auto-populated in the number field of new task?

then do this

It should be client side UI action

I assume u_number field on sc_task refers to sc_req_item table

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