title: Javascript / MS Dynamics CRM 2016: Changing value of option set field using confirm box
body: <p>I have an option set field in Dynamics CRM that has two values: "In Progress" (default) and "Completed". Using JavaScript, I want to issue a confirm box that triggers during the field event OnChange. The confirm box warns the user that if the user has selected "Completed" it will lock all the other fields in the record. </p>
  
  <p>Anyway, I wrote my code such that the confirm box will set the value of the option set. For some reason, it is not changing the values of the field. If the user clicks "Completed" and when the user clicks 'Cancel' in the confirm box to confirm and validate, it would still set the field value to "Completed". Any reason why it would not set the field values? Here is my code: </p>
  
  <pre><code>function confirmTaskStatus() {
  if (Xrm.Page.getControl("moc_taskstatus").getDisabled()){
      var taskStatusValue;
      var message = "Do you want to set this Task to Completed? 
                    You cannot edit, change or add anything to the Project Task fields 
                    once it is set to Completed";
  
    if (confirm(message) == true) {
  
        taskStatusValue = 223770000; // Display Label = "Completed" 
        Xrm.Page.getControl("moc_taskstatus").setDisabled(true);
  
        } else {
  
        taskStatusValue = 223770001; // Display Label = "In Progress"
  
      }
  
      Xrm.Page.getAttribute("moc_taskstatus").setValue(taskStatusValue);
  
  
  }  
  }
  
  
  function saveTaskStatus() {
  window.setTimeout(confirmTaskStatus, 1000);
  }
  </code></pre>
  
  <p>Have mercy on me; I'm still quite new to scripting and Dynamics CRM. </p>