@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);

View solution in original post

newhand
Mega Sage

@Anna_Servicenow 

why not use List type field ?

 

Nisha15
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);