<?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 How to set a value on a field of the form or record in Developer articles</title>
    <link>https://www.servicenow.com/community/developer-articles/how-to-set-a-value-on-a-field-of-the-form-or-record/ta-p/2321005</link>
    <description>&lt;DIV class="separator" style="clear: both; text-align: left;"&gt;In this Article, you will learn how can you set a value on a field of a form on different conditions and scenarios.&lt;/DIV&gt;
&lt;H3 style="text-align: left;"&gt;Setting the field value on load of the form&lt;/H3&gt;
&lt;DIV&gt;&lt;STRONG&gt;Scenario: &lt;/STRONG&gt;When incident form is loaded then the value of Caller field should populated with logged in user.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Solution :&amp;nbsp;&lt;/STRONG&gt;This type of requirement can be achieved with Client Script as it needs to be set when form is loaded in the browser.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;U&gt;Script Type : Client Script&lt;/U&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;U&gt;&amp;nbsp;&lt;/U&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Name&lt;/STRONG&gt; : Populate Caller on the Incident&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Table &lt;/STRONG&gt;: Incident&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;UI Type&lt;/STRONG&gt; : All&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Type &lt;/STRONG&gt;: OnLoad&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Active&lt;/STRONG&gt; : True&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Global&lt;/STRONG&gt;: True&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Script&lt;/STRONG&gt; :&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function onLoad() {
    //Type appropriate comment here, and begin script below

    if (g_form.isNewRecord()) {

        var currentUser = g_user.userID;

        g_form.setValue('caller_id', currentUser);
    }
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;H3 style="text-align: left;"&gt;Setting the field value on change of a field&lt;/H3&gt;
&lt;DIV&gt;&lt;STRONG&gt;Scenario: &lt;/STRONG&gt;When incident form is loaded then the Assignment Group should be populated with &lt;STRONG&gt;Network&lt;/STRONG&gt; group.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Solution :&amp;nbsp;&lt;/STRONG&gt;This type of requirement can be achieved with Client Script as it needs to be set when value of Category field changes to Hardware.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;U&gt;Script Type : Client Script&lt;/U&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;U&gt;&amp;nbsp;&lt;/U&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Name&lt;/STRONG&gt; : Populate Caller on the Incident&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Table&lt;/STRONG&gt; : Incident&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;UI Type&lt;/STRONG&gt; : All&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Type&lt;/STRONG&gt; : OnChange&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Field&lt;/STRONG&gt;: Category&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Active &lt;/STRONG&gt;: True&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Global&lt;/STRONG&gt;: True&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Script&lt;/STRONG&gt; :&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    if (newValue == 'hardware') {
        //Setting SYSID OF Network Group
        g_form.setValue('assignment_group', '287ebd7da9fe198100f92cc8d1d2154e','Network'); 
    }

}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Wed, 23 Sep 2020 19:03:17 GMT</pubDate>
    <dc:creator>GTSNOW</dc:creator>
    <dc:date>2020-09-23T19:03:17Z</dc:date>
    <item>
      <title>How to set a value on a field of the form or record</title>
      <link>https://www.servicenow.com/community/developer-articles/how-to-set-a-value-on-a-field-of-the-form-or-record/ta-p/2321005</link>
      <description>&lt;DIV class="separator" style="clear: both; text-align: left;"&gt;In this Article, you will learn how can you set a value on a field of a form on different conditions and scenarios.&lt;/DIV&gt;
&lt;H3 style="text-align: left;"&gt;Setting the field value on load of the form&lt;/H3&gt;
&lt;DIV&gt;&lt;STRONG&gt;Scenario: &lt;/STRONG&gt;When incident form is loaded then the value of Caller field should populated with logged in user.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Solution :&amp;nbsp;&lt;/STRONG&gt;This type of requirement can be achieved with Client Script as it needs to be set when form is loaded in the browser.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;U&gt;Script Type : Client Script&lt;/U&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;U&gt;&amp;nbsp;&lt;/U&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Name&lt;/STRONG&gt; : Populate Caller on the Incident&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Table &lt;/STRONG&gt;: Incident&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;UI Type&lt;/STRONG&gt; : All&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Type &lt;/STRONG&gt;: OnLoad&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Active&lt;/STRONG&gt; : True&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Global&lt;/STRONG&gt;: True&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Script&lt;/STRONG&gt; :&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function onLoad() {
    //Type appropriate comment here, and begin script below

    if (g_form.isNewRecord()) {

        var currentUser = g_user.userID;

        g_form.setValue('caller_id', currentUser);
    }
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;H3 style="text-align: left;"&gt;Setting the field value on change of a field&lt;/H3&gt;
&lt;DIV&gt;&lt;STRONG&gt;Scenario: &lt;/STRONG&gt;When incident form is loaded then the Assignment Group should be populated with &lt;STRONG&gt;Network&lt;/STRONG&gt; group.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Solution :&amp;nbsp;&lt;/STRONG&gt;This type of requirement can be achieved with Client Script as it needs to be set when value of Category field changes to Hardware.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;U&gt;Script Type : Client Script&lt;/U&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;U&gt;&amp;nbsp;&lt;/U&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Name&lt;/STRONG&gt; : Populate Caller on the Incident&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Table&lt;/STRONG&gt; : Incident&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;UI Type&lt;/STRONG&gt; : All&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Type&lt;/STRONG&gt; : OnChange&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Field&lt;/STRONG&gt;: Category&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Active &lt;/STRONG&gt;: True&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Global&lt;/STRONG&gt;: True&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Script&lt;/STRONG&gt; :&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    if (newValue == 'hardware') {
        //Setting SYSID OF Network Group
        g_form.setValue('assignment_group', '287ebd7da9fe198100f92cc8d1d2154e','Network'); 
    }

}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 23 Sep 2020 19:03:17 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-articles/how-to-set-a-value-on-a-field-of-the-form-or-record/ta-p/2321005</guid>
      <dc:creator>GTSNOW</dc:creator>
      <dc:date>2020-09-23T19:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a value on a field of the form or record</title>
      <link>https://www.servicenow.com/community/developer-articles/how-to-set-a-value-on-a-field-of-the-form-or-record/tac-p/2321006#M3898</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;Can you update the g_form&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;setValue&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'assignment_group'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'287ebd7da9fe198100f92cc8d1d2154e'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&amp;nbsp; part?&lt;/P&gt;
&lt;P&gt;This now causes an additional query to be made (= waste of performance). Assignment Group is a reference field, so you should provide the value and the displayValue.&lt;/P&gt;
&lt;P class="ng-scope"&gt;Kind regards,&lt;BR /&gt;Mark&lt;BR /&gt;&lt;EM&gt;&lt;A href="https://community.servicenow.com/community?id=community_blog&amp;amp;sys_id=fb488720dbaacc504819fb2439961900" target="_blank" rel="noopener noreferrer nofollow"&gt;2020 ServiceNow Community MVP&lt;/A&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;A href="https://developer.servicenow.com/blog.do?p=/post/all-stars/" target="_blank" rel="noopener noreferrer nofollow"&gt;2020 ServiceNow Developer MVP&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P class="ng-scope"&gt;---&lt;/P&gt;
&lt;P class="ng-scope"&gt;&lt;A href="https://www.linkedin.com/in/markroethof/" target="_blank" rel="noopener noreferrer nofollow"&gt;LinkedIn&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://community.servicenow.com/community?id=community_blog&amp;amp;sys_id=14e51965db2200d013b5fb24399619fb" target="_blank" rel="noopener noreferrer nofollow"&gt;Community article list&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 19:12:18 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-articles/how-to-set-a-value-on-a-field-of-the-form-or-record/tac-p/2321006#M3898</guid>
      <dc:creator>Mark Roethof</dc:creator>
      <dc:date>2020-09-23T19:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a value on a field of the form or record</title>
      <link>https://www.servicenow.com/community/developer-articles/how-to-set-a-value-on-a-field-of-the-form-or-record/tac-p/2321007#M3899</link>
      <description>&lt;P&gt;Thanks for correcting it.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 19:25:55 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-articles/how-to-set-a-value-on-a-field-of-the-form-or-record/tac-p/2321007#M3899</guid>
      <dc:creator>GTSNOW</dc:creator>
      <dc:date>2020-09-23T19:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a value on a field of the form or record</title>
      <link>https://www.servicenow.com/community/developer-articles/how-to-set-a-value-on-a-field-of-the-form-or-record/tac-p/2321008#M3900</link>
      <description>&lt;P&gt;You can also just set the default value for the field to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;javascript:gs.getUserID();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 19:27:11 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-articles/how-to-set-a-value-on-a-field-of-the-form-or-record/tac-p/2321008#M3900</guid>
      <dc:creator>DrewW</dc:creator>
      <dc:date>2020-09-23T19:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a value on a field of the form or record</title>
      <link>https://www.servicenow.com/community/developer-articles/how-to-set-a-value-on-a-field-of-the-form-or-record/tac-p/3050099#M9665</link>
      <description>&lt;P&gt;hey, i am trying on change, but it doesnt work for me.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2024 13:51:38 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-articles/how-to-set-a-value-on-a-field-of-the-form-or-record/tac-p/3050099#M9665</guid>
      <dc:creator>jennv</dc:creator>
      <dc:date>2024-09-19T13:51:38Z</dc:date>
    </item>
  </channel>
</rss>

