<?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 Re: Client Script - Get value of boolean reference field in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592874#M249800</link>
    <description>&lt;P&gt;Nevertheless, getReference() practically unexpectedly more efficient that Wiki tells.Proved by Experience.&lt;/P&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 07 May 2015 11:40:54 GMT</pubDate>
    <dc:creator>Andrii</dc:creator>
    <dc:date>2015-05-07T11:40:54Z</dc:date>
    <item>
      <title>Client Script - Get value of boolean reference field</title>
      <link>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592868#M249794</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a request to require a related problem record before priority 1 and 2 incidents can be resolved, which we've accomplished with an onSubmit client script. But I'd like to restrict this to certain groups, while also making it easy for groups to 'opt in/out' of the functionality in the future. I created a new true/false field on the sys_user_group table, named u_require_problem, but I'm not able to pull the value of the field into my script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I added the field to the form and plan to hide it with a UI Policy, and have validated that the field is checked on the group for my test incidents.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lines 6 &amp;amp; 7 are where I'm trying to get the value of the new field so I can use it in line 9. The script successfully prevents resolution for P1/P2s with no related problem, but I haven't been able to successfully populate my probMgmt variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14309433235682388" jivemacro_uid="_14309433235682388"&gt;
&lt;P&gt;function onSubmit() {&lt;/P&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //If p1 or p2 incident state == resolved and problem ID is blank&lt;/P&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var pri = g_form.getValue('priority');&lt;/P&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var state = g_form.getValue('state');&lt;/P&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var prob = g_form.getValue('problem_id');&lt;/P&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var probMgmt = g_form.getValue('u_require_problem');&lt;/P&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alert(probMgmt);&lt;/P&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/P&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(state == '6' &amp;amp;&amp;amp; (pri == '1' || pri == '2') &amp;amp;&amp;amp; prob == ''){&lt;/P&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alert('A problem is required for all P1 and P2 incidents.');&lt;/P&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;&lt;/P&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried getValue, getDisplayValue and getBooleanValue (referenced in &lt;A href="http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#Field_Information_Methods" title="http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#Field_Information_Methods"&gt;GlideForm (g form) - ServiceNow Wiki&lt;/A&gt;), getBooleanValue returns a 'not a function' error on the form and the others return a null value. Is there an easier way to accomplish this?&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2015 18:56:55 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592868#M249794</guid>
      <dc:creator>jenritchie</dc:creator>
      <dc:date>2015-05-06T18:56:55Z</dc:date>
    </item>
    <item>
      <title>Re: Client Script - Get value of boolean reference field</title>
      <link>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592869#M249795</link>
      <description>&lt;P&gt;Are you trying to make it based on the currently logged in user or based on the assignment group on the Incident record?&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;If it's supposed to be based on the currently logged in user, then you would be better off creating a role and adding that to the groups you want to be required to have a related problem. Then you could use a g_user.hasRole('&amp;lt;role&amp;gt;') to see if the current user should be required to do it.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;If it's based on the assignment group, then you need to use a GlideRecord query to get the value of the field on the group record.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 06 May 2015 20:03:56 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592869#M249795</guid>
      <dc:creator>Shawn Dowler</dc:creator>
      <dc:date>2015-05-06T20:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: Client Script - Get value of boolean reference field</title>
      <link>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592870#M249796</link>
      <description>&lt;P&gt;The issue is likely because the field you are trying to access is in the related group table, I assume you are just showing this value on the form by dot walking. You really don't need it on the form to accomplish what you need. But you will need to get the related group record to check the value. Out of the box there is a client script on Incident that populates the incident location value with the callers location. I would look at that script, specifically how it's using getReference to get the caller user record to lookup the location value. You can use a similar approach to get the u_require_problem value from the group record. Another option is to make an Ajax call to lookup the value. &lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 07 May 2015 00:48:17 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592870#M249796</guid>
      <dc:creator>Michael Ritchie</dc:creator>
      <dc:date>2015-05-07T00:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: Client Script - Get value of boolean reference field</title>
      <link>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592871#M249797</link>
      <description>&lt;P&gt;The out of box location and caller vip scripts helped immensely, thank you! This is what I have going now, so far so good:&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14309681308647514" jivemacro_uid="_14309681308647514" modifiedtitle="true"&gt;
&lt;P&gt;function onSubmit() &amp;nbsp; {&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var group = g_form.getReference('assignment_group'); &lt;/P&gt;&lt;BR /&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var pri = g_form.getValue('priority');&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var state = g_form.getValue('state');&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var probID = g_form.getValue('problem_id');&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt; &amp;nbsp; if (group.u_require_problem == 'true' &amp;amp;&amp;amp; state == '6' &amp;amp;&amp;amp; (pri == '1' || pri == '2') &amp;amp;&amp;amp; probID == '') {&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alert('A problem is required for all P1 and P2 incidents.');&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;But I realize&lt;A title="ki.servicenow.com/index.php?title=GlideForm_(g_form)#getReference" href="http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#getReference"&gt; I'm doing exactly what the wiki tells me not to do.&lt;/A&gt; When I did it the right way with a callback function, everything seems to work up to the alert point, where the incident is resolved even when the alert is triggered. Is there an example of using getReference like this for an onSubmit script instead of an onChange?&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 07 May 2015 03:24:25 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592871#M249797</guid>
      <dc:creator>jenritchie</dc:creator>
      <dc:date>2015-05-07T03:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: Client Script - Get value of boolean reference field</title>
      <link>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592872#M249798</link>
      <description>&lt;P&gt;True, getReference is the function that should answer this question.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 07 May 2015 06:41:45 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592872#M249798</guid>
      <dc:creator>Andrii</dc:creator>
      <dc:date>2015-05-07T06:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: Client Script - Get value of boolean reference field</title>
      <link>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592873#M249799</link>
      <description>&lt;P&gt;The getReference() function requires a lookup to the server client side so it's not the most efficient, which is what the Wiki is telling you. Sometimes you cannot avoid it though. Fortunately you are making the call onSubmit which will occur less often than onChange or onLoad. &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Another alternative and maybe better one is to put this logic in the Resolve UI action. This way it performs the validation only when the ticket is being resolved. The out of the box Resolve Incident UI action performs some things client side and well as server side. It requires a comment, close code, and close notes. You could also have it check the flag in the group and require a problem as well. &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Either will work though. &lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 07 May 2015 10:50:12 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592873#M249799</guid>
      <dc:creator>Michael Ritchie</dc:creator>
      <dc:date>2015-05-07T10:50:12Z</dc:date>
    </item>
    <item>
      <title>Re: Client Script - Get value of boolean reference field</title>
      <link>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592874#M249800</link>
      <description>&lt;P&gt;Nevertheless, getReference() practically unexpectedly more efficient that Wiki tells.Proved by Experience.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 07 May 2015 11:40:54 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592874#M249800</guid>
      <dc:creator>Andrii</dc:creator>
      <dc:date>2015-05-07T11:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: Client Script - Get value of boolean reference field</title>
      <link>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592875#M249801</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Capture.PNG"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/195344i7D5F3C6505A416AD/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;getReference() function requires addition time, please use Glide Ajax to call Script Include.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 07 May 2015 11:53:54 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592875#M249801</guid>
      <dc:creator>gupta-amitg</dc:creator>
      <dc:date>2015-05-07T11:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: Client Script - Get value of boolean reference field</title>
      <link>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592876#M249802</link>
      <description>&lt;P&gt;Yes - you are right - getReference() requires additional time(theoreticaly, but practicaly - behaviour is different time to time) - but UI Action also takes time to connect to server. I just proposing a solution - let the person who asks to &amp;nbsp; define what will suite him the best.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 07 May 2015 12:30:23 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592876#M249802</guid>
      <dc:creator>Andrii</dc:creator>
      <dc:date>2015-05-07T12:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: Client Script - Get value of boolean reference field</title>
      <link>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592877#M249803</link>
      <description>&lt;P&gt;Let me try to explain why the callback function did not work...&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;The glidereference with a callback function is similar to glideajax with getXML function.. The client script makes a call to the server but since callback function is async in nature, it will not wait for the response from the server and the form continues to the submission. So there are cases where you will need to pick and choose between a async call and sync call ... &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Usually, onload function are better left to async calls and onsubmit with sync ones...&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Long story short, use a getreference without callback function in onsubmit script ....&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 07 May 2015 14:34:10 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/client-script-get-value-of-boolean-reference-field/m-p/1592877#M249803</guid>
      <dc:creator>Kalaiarasan Pus</dc:creator>
      <dc:date>2015-05-07T14:34:10Z</dc:date>
    </item>
  </channel>
</rss>

