<?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 Hiding Form Fields using Business Script in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/hiding-form-fields-using-business-script/m-p/1430898#M87824</link>
    <description>&lt;P&gt;I am currently using a display business rule and a client script to hide 3 fields on a form.&amp;nbsp; The issue is, when the form loads, these fields are visible for a few seconds and then just disappear, leave blank space on the form.&lt;/P&gt;
&lt;P&gt;While this works, I was wondering if there was a better way to do this so the blank space that is taken up by these fields disappears as well.&amp;nbsp; I'd rather the fields below these ones move up to fill the space instead of leaving a large blank space on the form.&lt;/P&gt;
&lt;P&gt;Also, is there a different way to do this that will prevent the fields from showing up for the fraction of a second they appear for before the business rule runs?&lt;/P&gt;
&lt;P&gt;The part in the red rectangle is what I'd like to fill with the fields under it.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/154982i33F74B1AC148CD76/image-size/large?v=v2&amp;amp;px=999" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Current code to hide the fields:&lt;/P&gt;
&lt;P&gt;Display BR:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;(function executeRule(current, previous /*null when async*/) {

	g_scratchpad.isMember = gs.getUser().isMemberOf('HR Payroll');

})(current, previous);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Client Script:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function onLoad(){

if(g_scratchpad.isMember.toString() == 'false'){

// hide your fields one by one

g_form.setVisible('u_run_type', false); // your field name here
g_form.setVisible('u_year', false); // your field name here
g_form.setVisible('u_pay_period', false); // your field name here
}

}&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 24 Jan 2022 19:09:58 GMT</pubDate>
    <dc:creator>Staxed</dc:creator>
    <dc:date>2022-01-24T19:09:58Z</dc:date>
    <item>
      <title>Hiding Form Fields using Business Script</title>
      <link>https://www.servicenow.com/community/developer-forum/hiding-form-fields-using-business-script/m-p/1430898#M87824</link>
      <description>&lt;P&gt;I am currently using a display business rule and a client script to hide 3 fields on a form.&amp;nbsp; The issue is, when the form loads, these fields are visible for a few seconds and then just disappear, leave blank space on the form.&lt;/P&gt;
&lt;P&gt;While this works, I was wondering if there was a better way to do this so the blank space that is taken up by these fields disappears as well.&amp;nbsp; I'd rather the fields below these ones move up to fill the space instead of leaving a large blank space on the form.&lt;/P&gt;
&lt;P&gt;Also, is there a different way to do this that will prevent the fields from showing up for the fraction of a second they appear for before the business rule runs?&lt;/P&gt;
&lt;P&gt;The part in the red rectangle is what I'd like to fill with the fields under it.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/154982i33F74B1AC148CD76/image-size/large?v=v2&amp;amp;px=999" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Current code to hide the fields:&lt;/P&gt;
&lt;P&gt;Display BR:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;(function executeRule(current, previous /*null when async*/) {

	g_scratchpad.isMember = gs.getUser().isMemberOf('HR Payroll');

})(current, previous);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Client Script:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function onLoad(){

if(g_scratchpad.isMember.toString() == 'false'){

// hide your fields one by one

g_form.setVisible('u_run_type', false); // your field name here
g_form.setVisible('u_year', false); // your field name here
g_form.setVisible('u_pay_period', false); // your field name here
}

}&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Jan 2022 19:09:58 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/hiding-form-fields-using-business-script/m-p/1430898#M87824</guid>
      <dc:creator>Staxed</dc:creator>
      <dc:date>2022-01-24T19:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Hiding Form Fields using Business Script</title>
      <link>https://www.servicenow.com/community/developer-forum/hiding-form-fields-using-business-script/m-p/1430899#M87825</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Please use:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;setDisplay&lt;/STRONG&gt; instead of &lt;SPAN style="color: #ff0000;"&gt;setVisible&lt;/SPAN&gt;.&lt;/P&gt;
&lt;P&gt;As far as timing is concerned, that is all dependent on the client and the form loading process.&lt;/P&gt;
&lt;P&gt;You may want to review all of your client scripts, etc. and see if there's a way to streamline the process or consider setting this specific client script to a lower order number so it executes first.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Please mark reply as Helpful/Correct, if applicable. Thanks!&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 19:12:38 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/hiding-form-fields-using-business-script/m-p/1430899#M87825</guid>
      <dc:creator>Allen Andreas</dc:creator>
      <dc:date>2022-01-24T19:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: Hiding Form Fields using Business Script</title>
      <link>https://www.servicenow.com/community/developer-forum/hiding-form-fields-using-business-script/m-p/1430900#M87826</link>
      <description>&lt;P&gt;That was simple, thanks!&amp;nbsp; You don't happen to know a better way to do this that might prevent the fields from showing up for about a second before the business rule runs do you?&lt;/P&gt;
&lt;P&gt;Also, I've tried a few different ways and can't seem to figure it out, how would I go about changing my Business Rule to check for multiple group memberships instead of just the one?&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 19:16:14 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/hiding-form-fields-using-business-script/m-p/1430900#M87826</guid>
      <dc:creator>Staxed</dc:creator>
      <dc:date>2022-01-24T19:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: Hiding Form Fields using Business Script</title>
      <link>https://www.servicenow.com/community/developer-forum/hiding-form-fields-using-business-script/m-p/1430901#M87827</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I wrote a bit more above (in an edit) about the timing issue. Please review that.&lt;/P&gt;
&lt;P&gt;As far as adjusting your business rule script, you could do (there's a few ways to do it, but one is):&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;if (gs.getUser().isMemberOf('HR Payroll') &amp;gt; -1 || gs.getUser().isMemberOf('Group 2') &amp;gt; -1 || gs.getUser().isMemberOf('Group 3') &amp;gt; -1) {
g_scratchpad.isMember = true;
} else {
g_scratchpad.isMember = false;
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Please mark reply as Helpful, if applicable. Thanks!&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 19:23:34 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/hiding-form-fields-using-business-script/m-p/1430901#M87827</guid>
      <dc:creator>Allen Andreas</dc:creator>
      <dc:date>2022-01-24T19:23:34Z</dc:date>
    </item>
  </channel>
</rss>

