The CreatorCon Call for Content is officially open! Get started here.

Shamma Negi
Kilo Sage
Kilo Sage

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

 

2. Inserting a record in group roles tables

 

var grGrpRole=new GlideRecord('sys_group_has_role');
grGrpRole.initialize();
grGrpRole.group.setDisplayValue('application development');
grGrpRole.role.setDisplayValue('agent_workspace_user');
grGrpRole.insert();

 

 

Hope this helps you.

I hope this article helpful. Please mark it as helpful and bookmark if you like it.

 

Regards,

Shamma Negi