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


var changeRequest = ChangeRequest.newEmergency();
changeRequest.setValue("type", 'ocean_medallion_emergency');
changeRequest.setValue("short_description", current.short_description);
changeRequest.setValue("description", current.description);
changeRequest.setValue("cmdb_ci", current.cmdb_ci);
changeRequest.setValue("priority", current.priority);
changeRequest.setValue("sys_domain", current.sys_domain);
changeRequest.setValue("company", current.company);
changeRequest.setValue("assignment_group", current.cmdb_ci.support_group);
var al = current.getDisplayValue('u_om_affected_location');
changeRequest.setDisplayValue("u_affected_locations", al);
changeRequest.u_brands_affected = current.u_brands_affected;
// 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.u_brands_affected = current.u_brands_affected;
// }
changeRequest.setDisplayValue("u_reason_for_invoking_change", "Incident");
changeRequest.setDisplayValue("u_environment", "Production");

Can you try

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

It did work! Thanks a lot.. I didn't have to use arrays at all.Great 🙂

Appreciate your help!