<?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 Confusion on using &amp;quot;&amp;&amp;&amp;quot; &amp;quot; || &amp;quot; in onload client script in ITSM forum</title>
    <link>https://www.servicenow.com/community/itsm-forum/confusion-on-using-quot-quot-quot-quot-in-onload-client-script/m-p/599727#M171506</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I have 5 state fields on custom table and I have got a requirement like, making the fields read-only for user in 3,4,5 states. I have written onLoad script for this, but I got&amp;nbsp;confused&amp;nbsp;in using the Logical operator.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Initially I have tried like below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;if(g_user.hasRole('u_matter_management_user') &amp;amp;&amp;amp; (g_form.getValue('state') != '-3' || g_form.getValue('state') != '-2'))&lt;/P&gt;
&lt;P&gt;It didn't worked.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Later I tried like below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;if(g_user.hasRole('u_matter_management_user') &amp;amp;&amp;amp; (g_form.getValue('state') != '-3' &amp;amp;&amp;amp; g_form.getValue('state') != '-2'))&lt;/P&gt;
&lt;P&gt;It is working. My doubt here is, we are saying either of the states right, so I though to Use OR condition, but didn't work. Could anybody please explain on these operators.&lt;/P&gt;
&lt;P&gt;If AND is to be used, I have written a script to make all fields read-only in closed states, using OR condition which is working fine.&lt;/P&gt;
&lt;P&gt;function onLoad() {&lt;BR /&gt; //Type appropriate comment here, and begin script below&lt;BR /&gt; if(!g_user.hasRole("admin") &amp;amp;&amp;amp; (g_form.getValue("state")==4 || g_form.getValue("state")==5 || g_form.getValue("state")==6)) {&lt;BR /&gt; var fields = g_form.getEditableFields();&lt;BR /&gt; for (var x = 0; x &amp;lt; fields.length; x++) {&lt;BR /&gt; g_form.setReadOnly(fields[x], true);&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Here I have used OR condition only, and it is working fine. But why it is not working in first requirement.&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Dec 2020 18:28:43 GMT</pubDate>
    <dc:creator>Ajay37</dc:creator>
    <dc:date>2020-12-01T18:28:43Z</dc:date>
    <item>
      <title>Confusion on using "&amp;&amp;" " || " in onload client script</title>
      <link>https://www.servicenow.com/community/itsm-forum/confusion-on-using-quot-quot-quot-quot-in-onload-client-script/m-p/599727#M171506</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I have 5 state fields on custom table and I have got a requirement like, making the fields read-only for user in 3,4,5 states. I have written onLoad script for this, but I got&amp;nbsp;confused&amp;nbsp;in using the Logical operator.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Initially I have tried like below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;if(g_user.hasRole('u_matter_management_user') &amp;amp;&amp;amp; (g_form.getValue('state') != '-3' || g_form.getValue('state') != '-2'))&lt;/P&gt;
&lt;P&gt;It didn't worked.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Later I tried like below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;if(g_user.hasRole('u_matter_management_user') &amp;amp;&amp;amp; (g_form.getValue('state') != '-3' &amp;amp;&amp;amp; g_form.getValue('state') != '-2'))&lt;/P&gt;
&lt;P&gt;It is working. My doubt here is, we are saying either of the states right, so I though to Use OR condition, but didn't work. Could anybody please explain on these operators.&lt;/P&gt;
&lt;P&gt;If AND is to be used, I have written a script to make all fields read-only in closed states, using OR condition which is working fine.&lt;/P&gt;
&lt;P&gt;function onLoad() {&lt;BR /&gt; //Type appropriate comment here, and begin script below&lt;BR /&gt; if(!g_user.hasRole("admin") &amp;amp;&amp;amp; (g_form.getValue("state")==4 || g_form.getValue("state")==5 || g_form.getValue("state")==6)) {&lt;BR /&gt; var fields = g_form.getEditableFields();&lt;BR /&gt; for (var x = 0; x &amp;lt; fields.length; x++) {&lt;BR /&gt; g_form.setReadOnly(fields[x], true);&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Here I have used OR condition only, and it is working fine. But why it is not working in first requirement.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 18:28:43 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/confusion-on-using-quot-quot-quot-quot-in-onload-client-script/m-p/599727#M171506</guid>
      <dc:creator>Ajay37</dc:creator>
      <dc:date>2020-12-01T18:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Confusion on using "&amp;&amp;" " || " in onload client script</title>
      <link>https://www.servicenow.com/community/itsm-forum/confusion-on-using-quot-quot-quot-quot-in-onload-client-script/m-p/599728#M171507</link>
      <description>&lt;P&gt;you need below&lt;/P&gt;
&lt;P&gt;if(g_user.hasRole('u_matter_management_user') &amp;amp;&amp;amp; (g_form.getValue('state') != '-3' &lt;SPAN style="background-color: #ffff00;"&gt;&lt;STRONG&gt;&amp;amp;&amp;amp;&lt;/STRONG&gt;&lt;/SPAN&gt; g_form.getValue('state') != '-2'))&lt;/P&gt;
&lt;P&gt;Basically your condition is saying state is not -3 and not -2 so that shows you all other state items.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you use != then you have to use &amp;amp;&amp;amp; instead of || so you get results without those 2 states&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 18:31:00 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/confusion-on-using-quot-quot-quot-quot-in-onload-client-script/m-p/599728#M171507</guid>
      <dc:creator>Mike Patel</dc:creator>
      <dc:date>2020-12-01T18:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: Confusion on using "&amp;&amp;" " || " in onload client script</title>
      <link>https://www.servicenow.com/community/itsm-forum/confusion-on-using-quot-quot-quot-quot-in-onload-client-script/m-p/599729#M171508</link>
      <description>&lt;P&gt;Thanks Mike,&lt;/P&gt;
&lt;P&gt;Yes I used that, I just confused about using OR and AND. We are saying like either of the state fields, so as per this we need to use OR right, if we use AND it is saying like when state is not both -3 and -2. I am really confused with this concept, could you please explain clearly.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 18:37:03 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/confusion-on-using-quot-quot-quot-quot-in-onload-client-script/m-p/599729#M171508</guid>
      <dc:creator>Ajay37</dc:creator>
      <dc:date>2020-12-01T18:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Confusion on using "&amp;&amp;" " || " in onload client script</title>
      <link>https://www.servicenow.com/community/itsm-forum/confusion-on-using-quot-quot-quot-quot-in-onload-client-script/m-p/599730#M171509</link>
      <description>&lt;P&gt;I know it's little confusing but if you think about it is working as it should.&lt;/P&gt;
&lt;P&gt;When you use OR then all tickets will show up because you are saying if the ticket is not in -3 state or -2 state then show.&lt;/P&gt;
&lt;P&gt;The other you can look at it like if state is -3 and -2 then show results then it will only show tickets that are not in either state.&lt;/P&gt;
&lt;P&gt;Refer to (page 10 and 11)- &lt;A href="https://www.servicenow.com/content/dam/servicenow/other-documents/training/ServiceNow-JavaScript-Primer.pdf" rel="nofollow"&gt;https://www.servicenow.com/content/dam/servicenow/other-documents/training/ServiceNow-JavaScript-Primer.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence" rel="nofollow"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 18:43:07 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/confusion-on-using-quot-quot-quot-quot-in-onload-client-script/m-p/599730#M171509</guid>
      <dc:creator>Mike Patel</dc:creator>
      <dc:date>2020-12-01T18:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: Confusion on using "&amp;&amp;" " || " in onload client script</title>
      <link>https://www.servicenow.com/community/itsm-forum/confusion-on-using-quot-quot-quot-quot-in-onload-client-script/m-p/599731#M171510</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;The line&lt;EM&gt; g_form.getValue('state') != '-3' || g_form.getValue('state') != '-2' &lt;/EM&gt;will&amp;nbsp;check for state should not be -3 &lt;STRONG&gt;or&lt;/STRONG&gt; state should not be -2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The line&lt;EM&gt;&amp;nbsp;g_form.getValue('state') != '-3' &amp;amp;&amp;amp; g_form.getValue('state') != '-2'&amp;nbsp;&lt;/EM&gt;will&amp;nbsp;check for state should not be -3 &lt;STRONG&gt;and&lt;/STRONG&gt;&amp;nbsp;-2 as well.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 18:43:33 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/confusion-on-using-quot-quot-quot-quot-in-onload-client-script/m-p/599731#M171510</guid>
      <dc:creator>Onkar Pandav</dc:creator>
      <dc:date>2020-12-01T18:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: Confusion on using "&amp;&amp;" " || " in onload client script</title>
      <link>https://www.servicenow.com/community/itsm-forum/confusion-on-using-quot-quot-quot-quot-in-onload-client-script/m-p/599732#M171511</link>
      <description>&lt;P&gt;Thanks Mike. I learned new things.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 10:14:50 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/confusion-on-using-quot-quot-quot-quot-in-onload-client-script/m-p/599732#M171511</guid>
      <dc:creator>Ajay37</dc:creator>
      <dc:date>2020-12-02T10:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: Confusion on using "&amp;&amp;" " || " in onload client script</title>
      <link>https://www.servicenow.com/community/itsm-forum/confusion-on-using-quot-quot-quot-quot-in-onload-client-script/m-p/599733#M171512</link>
      <description>&lt;P&gt;Thanks for reply Onkar.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 10:15:18 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/confusion-on-using-quot-quot-quot-quot-in-onload-client-script/m-p/599733#M171512</guid>
      <dc:creator>Ajay37</dc:creator>
      <dc:date>2020-12-02T10:15:18Z</dc:date>
    </item>
  </channel>
</rss>

