JavaScript Javascript / MS Dynamics CRM 2016: Changing value of option set field using confirm box dynamics 2016 javascript

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.

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:

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);
}

Have mercy on me; I'm still quite new to scripting and Dynamics CRM.

Answer:1

I have a page with two textareas and two buttons that copy the content of each textarea respectively to the user's clipboard when pressed. When the button is pressed and the copying is successful, a ...

I have a page with two textareas and two buttons that copy the content of each textarea respectively to the user's clipboard when pressed. When the button is pressed and the copying is successful, a ...

I am having trouble with noUislider, in that I need to be able to differentiate between different sliders when slide events are triggered. I thought (and from reading the noUiSlider GitHub) that I'd ...

I am having trouble with noUislider, in that I need to be able to differentiate between different sliders when slide events are triggered. I thought (and from reading the noUiSlider GitHub) that I'd ...

  1. nouislider slide event

I have this array and I want to count total numbers into this, can anyone please let me know how can i achieve this using pure javascript var total = { "numbers":{ "1":"9897877884", ...

I have this array and I want to count total numbers into this, can anyone please let me know how can i achieve this using pure javascript var total = { "numbers":{ "1":"9897877884", ...

  1. count length array php
  2. count length array javascript
  3. count length array python
  4. count length array jquery
  5. count length array
  6. count length array java
  7. count length array vba
  8. count length array angularjs
  9. count array length in c#
  10. count array length js
  11. count array length mongodb
  12. count array length online
  13. count array length in angular 4
  14. count array length in typescript
  15. count array length bash
  16. count array length powershell
  17. count array length in twig
  18. count array length in angular 6
  19. count length of array in react
  20. laravel count array length

I have successfully uploaded files to Firebase's storage via Google Cloud Storage through JS! What I noticed is that unlike files uploaded directly, the files uploaded through Google Cloud only have a ...

I have successfully uploaded files to Firebase's storage via Google Cloud Storage through JS! What I noticed is that unlike files uploaded directly, the files uploaded through Google Cloud only have a ...