<?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>question onLoad Catalog Client Script - Populate Variables in ITSM forum</title>
    <link>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693632#M265411</link>
    <description>&lt;P&gt;I'm trying to write an OnLoad Client Script for a catalog item. On the form we have two reference fields to the sys_user table. One is called Requestor (u_requestor) and the other is On Behalf Of (mrb_on_behalf_of) - this field can be used if someone needs to request access for someone else.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;If this field is populated I want it to populate some fields with that users details (mrb_on_behalf_of), if that field is not filled in then I want it to populate the fields with the Requestors user details (u_requestor). I've got the below script, however it's only working for the Requestors details and not the On Behalf Of. The reason I am using on load is because we're using an order guide and the same variables are on the catalog items.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;function onLoad(control, oldValue, newValue, isLoading) {&lt;BR /&gt; if (isLoading || newValue == '') {&lt;BR /&gt; return;&lt;BR /&gt; &lt;BR /&gt; }&lt;BR /&gt;var name = g_form.getReference('mrb_on_behalf_of');&lt;BR /&gt; if (name ==null){&lt;BR /&gt; userObject = g_form.getReference('u_requestor',setUserInfo);}&lt;BR /&gt; else {&lt;BR /&gt; userObject = g_form.getReference('mrb_on_behalf_of',setUserInfo);}&lt;/P&gt;
&lt;P&gt;function setUserInfo(userObject){&lt;BR /&gt; g_form.setValue('division',userObject.u_division);&lt;BR /&gt; g_form.setValue('position_title_02',userObject.title);&lt;BR /&gt; g_form.setValue('department',userObject.department);&lt;BR /&gt; &lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
    <pubDate>Mon, 10 Aug 2020 04:43:27 GMT</pubDate>
    <dc:creator>Casey9</dc:creator>
    <dc:date>2020-08-10T04:43:27Z</dc:date>
    <item>
      <title>onLoad Catalog Client Script - Populate Variables</title>
      <link>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693632#M265411</link>
      <description>&lt;P&gt;I'm trying to write an OnLoad Client Script for a catalog item. On the form we have two reference fields to the sys_user table. One is called Requestor (u_requestor) and the other is On Behalf Of (mrb_on_behalf_of) - this field can be used if someone needs to request access for someone else.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;If this field is populated I want it to populate some fields with that users details (mrb_on_behalf_of), if that field is not filled in then I want it to populate the fields with the Requestors user details (u_requestor). I've got the below script, however it's only working for the Requestors details and not the On Behalf Of. The reason I am using on load is because we're using an order guide and the same variables are on the catalog items.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;function onLoad(control, oldValue, newValue, isLoading) {&lt;BR /&gt; if (isLoading || newValue == '') {&lt;BR /&gt; return;&lt;BR /&gt; &lt;BR /&gt; }&lt;BR /&gt;var name = g_form.getReference('mrb_on_behalf_of');&lt;BR /&gt; if (name ==null){&lt;BR /&gt; userObject = g_form.getReference('u_requestor',setUserInfo);}&lt;BR /&gt; else {&lt;BR /&gt; userObject = g_form.getReference('mrb_on_behalf_of',setUserInfo);}&lt;/P&gt;
&lt;P&gt;function setUserInfo(userObject){&lt;BR /&gt; g_form.setValue('division',userObject.u_division);&lt;BR /&gt; g_form.setValue('position_title_02',userObject.title);&lt;BR /&gt; g_form.setValue('department',userObject.department);&lt;BR /&gt; &lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 04:43:27 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693632#M265411</guid>
      <dc:creator>Casey9</dc:creator>
      <dc:date>2020-08-10T04:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: onLoad Catalog Client Script - Populate Variables</title>
      <link>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693633#M265412</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function onLoad() {

var userObject;
var name = g_form.getReference('mrb_on_behalf_of');
if (name ==null || name == '' ){
userObject = g_form.getReference('u_requestor',setUserInfo);}
else {
userObject = g_form.getReference('mrb_on_behalf_of',setUserInfo);}

function setUserInfo(userObject){
g_form.setValue('division',userObject.u_division);
g_form.setValue('position_title_02',userObject.title);
g_form.setValue('department',userObject.department);

}


}

 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Aug 2020 04:49:37 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693633#M265412</guid>
      <dc:creator>MrMuhammad</dc:creator>
      <dc:date>2020-08-10T04:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: onLoad Catalog Client Script - Populate Variables</title>
      <link>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693634#M265413</link>
      <description>&lt;P&gt;You should remove the&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;if (isLoading || newValue == '') {
        return;

    }&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is exiting the script when it is loading, something you do not want to do on an onload client script.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 04:53:52 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693634#M265413</guid>
      <dc:creator>Willem</dc:creator>
      <dc:date>2020-08-10T04:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: onLoad Catalog Client Script - Populate Variables</title>
      <link>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693635#M265414</link>
      <description>&lt;P&gt;Hi Muhammad,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks for the suggestion, unfortunately that didn't work. Still only populating the Requestor details.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 05:11:36 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693635#M265414</guid>
      <dc:creator>Casey9</dc:creator>
      <dc:date>2020-08-10T05:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: onLoad Catalog Client Script - Populate Variables</title>
      <link>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693636#M265415</link>
      <description>&lt;P&gt;Can you try this:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function onLoad(control, oldValue, newValue, isLoading) {
    var name = g_form.getValue('mrb_on_behalf_of');
    if (name) {
        userObject = g_form.getReference('mrb_on_behalf_of', setUserInfo);
    }
    else{
        userObject = g_form.getReference('u_requestor', setUserInfo);
    }

    function setUserInfo(userObject) {
        g_form.setValue('division', userObject.u_division);
        g_form.setValue('position_title_02', userObject.title);
        g_form.setValue('department', userObject.department);
    }
}&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Aug 2020 05:23:04 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693636#M265415</guid>
      <dc:creator>Willem</dc:creator>
      <dc:date>2020-08-10T05:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: onLoad Catalog Client Script - Populate Variables</title>
      <link>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693637#M265416</link>
      <description>&lt;P&gt;Hi Casey&lt;/P&gt;
&lt;P&gt;just a tip, how we manage this:&lt;/P&gt;
&lt;P&gt;Requested By field: readonly(using onload)&lt;/P&gt;
&lt;P&gt;Requested For field: editable field&lt;/P&gt;
&lt;P&gt;First of all create a onLoad script :&lt;/P&gt;
&lt;P&gt;function onLoad() {&lt;/P&gt;
&lt;P&gt;var user;&lt;BR /&gt;var name = g_form.getReference('mrb_on_behalf_of');&lt;BR /&gt;if (name ==null || name == '' )&lt;/P&gt;
&lt;P&gt;{&lt;BR /&gt;user = g_form.getReference('u_requestor',setUserInfo);&lt;/P&gt;
&lt;P&gt;}&lt;BR /&gt;else&lt;/P&gt;
&lt;P&gt;{&lt;BR /&gt;user = g_form.getReference('mrb_on_behalf_of',setUser);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;function setUser(userObject){&lt;BR /&gt;g_form.setValue('division',user.u_division);&lt;BR /&gt;g_form.setValue('position_title_02',user.title);&lt;BR /&gt;g_form.setValue('department',user.department);&lt;/P&gt;
&lt;P&gt;}&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;Then create a onChange script on the Requested for field.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Sudhanshu&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 05:44:00 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693637#M265416</guid>
      <dc:creator>Sudhanshu Talw1</dc:creator>
      <dc:date>2020-08-10T05:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: onLoad Catalog Client Script - Populate Variables</title>
      <link>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693638#M265417</link>
      <description>&lt;P&gt;That did it!&lt;BR /&gt;&lt;BR /&gt;Thanks very much for that, Willem!&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 07:25:28 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693638#M265417</guid>
      <dc:creator>Casey9</dc:creator>
      <dc:date>2020-08-10T07:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: onLoad Catalog Client Script - Populate Variables</title>
      <link>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693639#M265418</link>
      <description>&lt;P&gt;You are very welcome! Thank you for marking the answer as correct. Can you also mark it as helpful?&lt;/P&gt;</description>
      <pubDate>Mon, 10 Aug 2020 07:36:32 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/onload-catalog-client-script-populate-variables/m-p/693639#M265418</guid>
      <dc:creator>Willem</dc:creator>
      <dc:date>2020-08-10T07:36:32Z</dc:date>
    </item>
  </channel>
</rss>

