JavascriptMS Dynamics CRM 2016: Changing value of option set field using confirm box - Stack Overflow

I have an option set field in Dynamics CRM that has two values: "In Progress" (default) and &

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.

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.

Share Improve this question edited Jun 16, 2016 at 23:08 12341234 asked Jun 16, 2016 at 22:58 1234123412341234 4046 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

It looks like the control is disabled (by looking at your code snippet). Disabled attributes SubmitMode is set to false, meaning, CRM will ignore any updates to the attribute unless you force CRM to save it by calling SetSubmitMode after the value is updated.

Xrm.Page.getAttribute("moc_taskstatus").setValue(taskStatusValue);
Xrm.Page.getAttribute("moc_taskstatus").setSubmitMode('always');

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745579214a4634153.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信