<?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 Clearing a variable once it's dependent variable changes not working in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/clearing-a-variable-once-it-s-dependent-variable-changes-not/m-p/2812674#M1079430</link>
    <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;I have a requirement for a record producer as mentioned below:&lt;/P&gt;&lt;P&gt;I have created two variables in a record producer. The first variable is a Reference type and the second variable is also a reference type variable. For the second variable, I'm using a custom table and a reference qualifier to populate values from the first variable's reference table.&lt;/P&gt;&lt;P&gt;When the first variable value is changed, the second variable value should also be changed. But the second variable's value is not changing.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="I1.png" style="width: 999px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/326332iE3EA4957D18E4D71/image-size/large?v=v2&amp;amp;px=999" role="button" title="I1.png" alt="I1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have created an onChange client script but it's not working.&lt;/P&gt;&lt;P&gt;Let me know if I'm missing anything.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="I2.png" style="width: 999px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/326333iD321DB36B9230C22/image-size/large?v=v2&amp;amp;px=999" role="button" title="I2.png" alt="I2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Amol&lt;/P&gt;</description>
    <pubDate>Fri, 02 Feb 2024 04:56:16 GMT</pubDate>
    <dc:creator>amolpawar</dc:creator>
    <dc:date>2024-02-02T04:56:16Z</dc:date>
    <item>
      <title>Clearing a variable once it's dependent variable changes not working</title>
      <link>https://www.servicenow.com/community/developer-forum/clearing-a-variable-once-it-s-dependent-variable-changes-not/m-p/2812674#M1079430</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;I have a requirement for a record producer as mentioned below:&lt;/P&gt;&lt;P&gt;I have created two variables in a record producer. The first variable is a Reference type and the second variable is also a reference type variable. For the second variable, I'm using a custom table and a reference qualifier to populate values from the first variable's reference table.&lt;/P&gt;&lt;P&gt;When the first variable value is changed, the second variable value should also be changed. But the second variable's value is not changing.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="I1.png" style="width: 999px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/326332iE3EA4957D18E4D71/image-size/large?v=v2&amp;amp;px=999" role="button" title="I1.png" alt="I1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have created an onChange client script but it's not working.&lt;/P&gt;&lt;P&gt;Let me know if I'm missing anything.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="I2.png" style="width: 999px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/326333iD321DB36B9230C22/image-size/large?v=v2&amp;amp;px=999" role="button" title="I2.png" alt="I2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Amol&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 04:56:16 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/clearing-a-variable-once-it-s-dependent-variable-changes-not/m-p/2812674#M1079430</guid>
      <dc:creator>amolpawar</dc:creator>
      <dc:date>2024-02-02T04:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: Clearing a variable once it's dependent variable changes not working</title>
      <link>https://www.servicenow.com/community/developer-forum/clearing-a-variable-once-it-s-dependent-variable-changes-not/m-p/2812689#M1079434</link>
      <description>&lt;P&gt;Hi &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/126675"&gt;@amolpawar&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;since it is reference field clearValue will not work, you need to use setValue&lt;/P&gt;&lt;P&gt;use g_form.setValue('fieldname',''); // clear the value&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;additional note you can place this line inside if at line 2&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; (isLoading || newValue === &lt;/SPAN&gt;&lt;SPAN&gt;''&lt;/SPAN&gt;&lt;SPAN&gt;) {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;P&gt;g_form.setValue('fieldname',''); // clear the value when first variable is empty&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 02 Feb 2024 05:10:25 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/clearing-a-variable-once-it-s-dependent-variable-changes-not/m-p/2812689#M1079434</guid>
      <dc:creator>Harish KM</dc:creator>
      <dc:date>2024-02-02T05:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: Clearing a variable once it's dependent variable changes not working</title>
      <link>https://www.servicenow.com/community/developer-forum/clearing-a-variable-once-it-s-dependent-variable-changes-not/m-p/2812711#M1079444</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/126675"&gt;@amolpawar&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;Please try below code:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
if (newValue) {
g_form.setValue('infosys_entity ', ' ');
}
}&lt;/LI-CODE&gt;&lt;P&gt;Please Mark &lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt;Correct if this solves your query and also mark &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;Helpful if you find my response worthy based on the impact.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Pratiksha&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 05:40:13 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/clearing-a-variable-once-it-s-dependent-variable-changes-not/m-p/2812711#M1079444</guid>
      <dc:creator>Pratiksha2</dc:creator>
      <dc:date>2024-02-02T05:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Clearing a variable once it's dependent variable changes not working</title>
      <link>https://www.servicenow.com/community/developer-forum/clearing-a-variable-once-it-s-dependent-variable-changes-not/m-p/2812769#M1079459</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/126675"&gt;@amolpawar&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;When working with reference-type variables, it's recommended to use the setValue function with an empty value for effective clearing, rather than relying on the clearValue function.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;You can refer the below code:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    if (newValue) {
        g_form.setValue('infosys_entity', '');  // Clear the value of 'infosys_entity'
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;BR /&gt;Kindly mark the answer &lt;/STRONG&gt;&lt;/EM&gt;&lt;span class="lia-unicode-emoji" title=":heavy_check_mark:"&gt;✔️&lt;/span&gt;&lt;EM&gt;&lt;STRONG&gt;Correct or Helpful &lt;/STRONG&gt;&lt;/EM&gt;&lt;span class="lia-unicode-emoji" title=":heavy_check_mark:"&gt;✔️&lt;/span&gt;&lt;EM&gt;&lt;STRONG&gt;If it addresses your concern.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;Regards,&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Aniket&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 06:09:16 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/clearing-a-variable-once-it-s-dependent-variable-changes-not/m-p/2812769#M1079459</guid>
      <dc:creator>AniketC85155510</dc:creator>
      <dc:date>2024-02-02T06:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Clearing a variable once it's dependent variable changes not working</title>
      <link>https://www.servicenow.com/community/developer-forum/clearing-a-variable-once-it-s-dependent-variable-changes-not/m-p/2812823#M1079467</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/126675"&gt;@amolpawar&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use Auto-Populate feature to achieve this without writing a single line of code. Refer below post and make the modifications accordingly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.servicenow.com/community/developer-articles/auto-populate-a-variable-based-on-a-reference-type-variable-utah/ta-p/2475511" target="_blank"&gt;https://www.servicenow.com/community/developer-articles/auto-populate-a-variable-based-on-a-reference-type-variable-utah/ta-p/2475511&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards&lt;/P&gt;&lt;P&gt;Amit Verma&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 06:32:04 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/clearing-a-variable-once-it-s-dependent-variable-changes-not/m-p/2812823#M1079467</guid>
      <dc:creator>vermaamit16</dc:creator>
      <dc:date>2024-02-02T06:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Clearing a variable once it's dependent variable changes not working</title>
      <link>https://www.servicenow.com/community/developer-forum/clearing-a-variable-once-it-s-dependent-variable-changes-not/m-p/2812938#M1079507</link>
      <description>&lt;P&gt;Thank you all of you for your quick reply,&lt;/P&gt;&lt;P&gt;I have marked helpful for the answer.&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 07:46:03 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/clearing-a-variable-once-it-s-dependent-variable-changes-not/m-p/2812938#M1079507</guid>
      <dc:creator>amolpawar</dc:creator>
      <dc:date>2024-02-02T07:46:03Z</dc:date>
    </item>
  </channel>
</rss>

