<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>post ServiceNow Learning 140: How can we use &amp;quot;setDisplayValue()&amp;quot; in server side scripting in ServiceNow? in Developer blog</title>
    <link>https://www.servicenow.com/community/developer-blog/servicenow-learning-140-how-can-we-use-quot-setdisplayvalue-quot/ba-p/2776630</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See the examples below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1. Update department as "Human Resources" for some particular record&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var userRecord = new GlideRecord('sys_user');&lt;BR /&gt;if (userRecord.get('sys_id', 'some_user_sys_id')) {&lt;BR /&gt;userRecord.setDisplayValue('department', 'Human Resources');&lt;BR /&gt;userRecord.update();&lt;BR /&gt;gs.info('Department updated for user: ' + userRecord.name);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2. Inserting a record in group roles tables&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var grGrpRole=new GlideRecord('sys_group_has_role');&lt;BR /&gt;grGrpRole.initialize();&lt;BR /&gt;grGrpRole.group.setDisplayValue('application development');&lt;BR /&gt;grGrpRole.role.setDisplayValue('agent_workspace_user');&lt;BR /&gt;grGrpRole.insert();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps you.&lt;/P&gt;&lt;P&gt;I hope this article helpful. Please mark it as helpful and bookmark if you like it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Shamma Negi&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jan 2024 08:41:52 GMT</pubDate>
    <dc:creator>Shamma Negi</dc:creator>
    <dc:date>2024-01-08T08:41:52Z</dc:date>
    <item>
      <title>ServiceNow Learning 140: How can we use "setDisplayValue()" in server side scripting in ServiceNow?</title>
      <link>https://www.servicenow.com/community/developer-blog/servicenow-learning-140-how-can-we-use-quot-setdisplayvalue-quot/ba-p/2776630</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See the examples below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1. Update department as "Human Resources" for some particular record&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var userRecord = new GlideRecord('sys_user');&lt;BR /&gt;if (userRecord.get('sys_id', 'some_user_sys_id')) {&lt;BR /&gt;userRecord.setDisplayValue('department', 'Human Resources');&lt;BR /&gt;userRecord.update();&lt;BR /&gt;gs.info('Department updated for user: ' + userRecord.name);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2. Inserting a record in group roles tables&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var grGrpRole=new GlideRecord('sys_group_has_role');&lt;BR /&gt;grGrpRole.initialize();&lt;BR /&gt;grGrpRole.group.setDisplayValue('application development');&lt;BR /&gt;grGrpRole.role.setDisplayValue('agent_workspace_user');&lt;BR /&gt;grGrpRole.insert();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2024 08:41:52 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-blog/servicenow-learning-140-how-can-we-use-quot-setdisplayvalue-quot/ba-p/2776630</guid>
      <dc:creator>Shamma Negi</dc:creator>
      <dc:date>2024-01-08T08:41:52Z</dc:date>
    </item>
  </channel>
</rss>

