How to get values enter in field to a single field as array

Anna_Servicenow
Tera Guru

I have below requirement, when case id is added/updated , it should be added to connect case IDs automatically in same order in format case id 1 , case id 2 etc.. How to achieve this?

 

Anna_Servicenow_0-1718940874613.png

 

1 ACCEPTED SOLUTION

Updated the script as below and it worked

 

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

    // Add your code here

    var myArray = [];
gs.info("case"+current.u_caseid_1);
if (current.u_caseid_1 != '') {
myArray[0] = current.u_caseid_1;
}
if (current.u_caseid_2 != '') {
myArray[1] = current.u_caseid_2;
}
if (current.u_caseid_3 != '') {
myArray[2] = current.u_caseid_3;
}

current.connect_case_ids_2 = myArray.toString();

gs.info("array"+myArray+":"+current.connect_case_ids_2);

View solution in original post

6 REPLIES 6

Tony Chatfield1
Kilo Patron

Hi, unfortunately your question\requirement is not clear in your post.
Can you update this thread with clearer\specific details of your requirement, so that the community can better understand and assist.

@Tony Chatfield1 updated the post and an image is added

Based on details provided a before update BR like this should work.

 

var myArray = ['NA', 'NA', 'NA'];

if (u_case_id_1 != '') {
myArray[0] = u_case_id_1;
}
if (u_case_id_2 != '') {
myArray[1] = u_case_id_2;
}
if (u_case_id_3 != '') {
myArray[2] = u_case_id_3;
}

current.u_connect_case_ids = myArray.toString();

//Note edited syntax error

 

 

Updated the script as below and it worked

 

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

    // Add your code here

    var myArray = [];
gs.info("case"+current.u_caseid_1);
if (current.u_caseid_1 != '') {
myArray[0] = current.u_caseid_1;
}
if (current.u_caseid_2 != '') {
myArray[1] = current.u_caseid_2;
}
if (current.u_caseid_3 != '') {
myArray[2] = current.u_caseid_3;
}

current.connect_case_ids_2 = myArray.toString();

gs.info("array"+myArray+":"+current.connect_case_ids_2);