How to set value in List field?

tyagisu
Mega Expert

Hi,

The requirement is to create an emergency change from Incident and transfer some of the field values from Incident to Change Request. I need to get the value from list field "u_brands_affected" on Incident and set those values in CR's list field "u_brands_affected". I could get the values but when I set these values, it only sets the last value from the list. However, I have noticed all the values are there in the log. 

This is the code I am using:

var al = current.getDisplayValue('u_om_affected_location');
changeRequest.setDisplayValue("u_affected_locations", al);

var list = current.getDisplayValue('u_brands_affected');
var array = list.split(",");
for (var i=0; i < array.length; i++) {
gs.log("Reference value is: " + array[i]);
//changeRequest.u_brands_affected += array[i];
//changeRequest.setDisplayValue("u_brands_affected", array[i]);
//changeRequest.push("u_brands_affected".sys_id.toString());
changeRequest.setValue("u_brands_affected", array[i]);
}

 

Thanks in Advance,

Su

1 ACCEPTED SOLUTION

Can you try

 changeRequest.setDisplayValue('u_brands_affected' , current.u_brands_affected.getDisplayValue());

View solution in original post

7 REPLIES 7

dvp
Mega Sage
Mega Sage

As you are using for loop to set the value and the way it is written is to overwrite previous value

 

Try this

changeRequest.u_brands_affected = current.u_brands_affected;

No, it didn't work inside the loop.

You don't need a loop

Can you share the script that you are currently working on

 

Script should be something like below

var al = current.getDisplayValue('u_om_affected_location');
changeRequest.setDisplayValue("u_affected_locations", al);

changeRequest.u_brands_affected = current.u_brands_affected;

 

This is what I used

var al = current.getDisplayValue('u_om_affected_location');
changeRequest.setDisplayValue("u_affected_locations", al);
changeRequest.u_brands_affected = current.u_brands_affected;