ServiceNow Learning 140: How can we use "setDisplayValue()" in server side scripting in ServiceNow?
Import
·
Jan 08, 2024
·
article
Hi All,
Today, I would like to cover how can we use "setdisplayValue()". This function is used when you are updating the reference field value and you are receiving the displayValue rather than the sys_id of the field value.
See the examples below:
1. Update department as "Human Resources" for some particular record
var userRecord = new GlideRecord('sys_user');if (userRecord.get('sys_id', 'some_user_sys_id')) {userRecord.setDisplayValue('department', 'Human Resources');userRecord.update();gs.info('Department updated for user: ' + userRecord.name);
}
View original source
https://www.servicenow.com/community/developer-blog/servicenow-learning-140-how-can-we-use-quot-setdisplayvalue-quot/ba-p/2776630