简体   繁体   English

Javascript / MS Dynamics CRM 2016:使用确认框更改选项集字段的值

[英]Javascript / MS Dynamics CRM 2016: Changing value of option set field using confirm box

I have an option set field in Dynamics CRM that has two values: "In Progress" (default) and "Completed". 我在Dynamics CRM中有一个选项集字段,该字段具有两个值:“进行中”(默认)和“已完成”。 Using JavaScript, I want to issue a confirm box that triggers during the field event OnChange. 我想使用JavaScript发出一个确认框,该框在现场事件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. 我还是脚本和Dynamics CRM的新手。

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. 禁用的属性SubmitMode设置为false,这意味着,除非您在值更新后通过调用SetSubmitMode强制CRM保存属性,否则CRM将忽略对该属性的任何更新。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM