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

newhand
Mega Sage

@Anna_Servicenow 

why not use List type field ?

 

Please mark my answer as correct and helpful based on Impact.

Nisha15
Mega Sage
Mega Sage

Hi @Anna_Servicenow ,

This is how you can achieve this. write business rule or client script per your requirement.

Nisha15_0-1718942085437.png

var caseId1 = 111;
var caseId2 = 200;
var caseId3 = 120;

// Concatenate the values with a comma separator
var caseIdArr = [caseId1, caseId2, caseId3].filter(Boolean).join(', ');

gs.print(caseIdArr);