CRM 2011 - 选项集上的简单Javascript确认框

时间:2013-10-10 14:58:57

标签: javascript dynamics-crm-2011

Javascript的新手 - 我搜索过但发现我的问题只有部分答案。

我在CRM实体上设置了YES / NO选项。当用户单击“是”时,我想要一个确认提示,显示OK / CANCEL确认。这部分工作正常,但如果用户单击CANCEL,我还希望选项设置为NO。我无法弄明白这一部分。

我的代码如下 - 请您指出附加代码应该去哪里,哪个选项在CANCEL点击时返回NO?非常感谢您的帮助:

function new_submitforapproval_onchange ()
{
var approval = confirm("confirm message here");
if (approval)
{
  alert("ok message here");
}
else
{
  alert("cancel message here");
}
}

1 个答案:

答案 0 :(得分:2)

更通用的解决方案可以是以下功能:

function confirmChange(eCxt, promptMessage, okMessage, cancelMessage) {
    var promptMessage = promptMessage || "This is the default prompt";
    var okMessage = okMessage || "ok message here";
    var cancelMessage = cancelMessage || "cancel message here";
    if (confirm(promptMessage)) {
        alert(okMessage);
    } else {
        alert(cancelMessage);
        eCxt.getEventSource().setValue(0); // This assumes the field is boolean. 
        //eCxt.getEventSource().setValue(null); // Change the above line to this if applicable to an OptionSet.
    }
}

eCxt 通过在事件处理程序对话框中勾选“将执行上下文作为第一个参数”框传递给该函数,对应的是/否字段到。

其他3个参数是可选的,可以使用相同事件处理程序对话框的逗号分隔列表字段进行设置。