title: Dynamics CRM 2016 Javascript fix
body: <p>I have the following situation in Dynamics CRM 2016.</p>
  
  <p>I am trying to create a JS web resource that will act on a dropdown field change. </p>
  
  <pre class="lang-js prettyprint-override"><code>function esitoappuntamento() {
    Xrm.Page.getAttribute("new_esito").addOnChange(myOnChange);
  
    function myOnChange() {
      if (Xrm.Page.getAttribute("new_esito").getSelectedOption().value == "100000006") {
        Xrm.Page.getControl("new_esitoapp").setVisible(false); 
        Xrm.Page.getAttribute("new_esitoapp").setRequiredLevel("none");
      }
      else {
        Xrm.Page.getControl("new_esitoapp").setVisible(true);  
        Xrm.Page.getAttribute("new_esitoapp").setRequiredLevel("required");
      }
    }
  }
  </code></pre>
  
  <p>I have the option set field <code>new_esito</code> with options/choices. What I want to do is to show the <code>new_esitoapp</code> field only when the form loads and the new_esito value is 100000006 and someone changes the value from 100000006 to something else from the remaining 7 choices.</p>
  
  <p>Otherwise if when the form loads the <code>new_esito</code> value is not 100000006, it should not show the <code>new_esitoapp</code> field independently from what I choose in the <code>new_esito</code> field from the 8 available choices.</p>
  
  <p>This is working partially as I need it to work, because it is working fine for the case when the form loads and the field value is 100000006.</p>
  
  <p>The problem is that it is still showing the <code>new_esitoapp</code> field even when the form loads and the value of <code>new_esito</code> is not 100000006 and I change it to something else.</p>
  
  <p>So the behavior should be:</p>
  
  <pre><code>Form load -&gt; new_esito = 100000006 -&gt; change new_esito -&gt; show new_esitoapp
  
  Form load -&gt; new_esito != 100000006 -&gt; change new_esito -&gt; no show new_esitoapp
  </code></pre>
  
  <p>Wrong behavior now is:</p>
  
  <pre><code>Form load -&gt; new_esito != 100000006 -&gt; change new_esito -&gt; show new_esitoapp
  </code></pre>
  
  <p>I hope I made myself clear about what I want to achieve.</p>
  
  <p>Looking forward to your replies.</p>
  
  <p>Regards</p>