0

我正在尝试创建JavaScript来打开对话框。Dynamics CRM:Javascript触发器打开对话框

一旦当前记录中名为'new_mstatus'的字段的值等于'无效'并且用户打算打开该记录,将打开对话框。

function opendialog() { 
    if(Xrm.Page.ui.getFormType() == 1) 
    { 
     Xrm.Page.data.entity.save(null); 
     return; 
    } 

    // If inactive then trigger dialog 
    if (Xrm.Page.getAttribute("new_mstatus").getValue() == 'Inactive') { 

     window.open("/" + Xrm.Page.context.getOrgUniqueName() + "/cs/dialog/rundialog.aspx?DialogId=%7b840D55C6-8307-450B-977F-6A9C9844CCE7%7d&EntityName=appointment&ObjectId=" + Xrm.Page.data.entity.getId()); 

     // Set as being displayed so it doesn't trigger again on load 
     Xrm.Page.getAttribute("new_displayeddialog").setValue(true); 

    } 
} 

但它不工作。即使没有错误弹出。

有人能帮我一个忙吗?

非常感谢。

+1

哪种类型是字段“new_mstatus”? – 2013-04-10 07:18:45

+1

你试过在IE中调试吗?然后,您可以一步一步地按照代码进行操作。 – 2013-04-10 07:47:51

+0

什么叫您的opendialog功能? – Daryl 2013-04-10 12:46:29

回答

0

问题是您正在检查选项集数值(用getValue函数)对字符串(在您的情况下为Inactive)。

所以,你有两种方式:

  • 查找Inactive的optionset值(这是正确的方式)
// assuming 900000000 is the value for Inactive 
if (Xrm.Page.getAttribute("new_mstatus").getValue() == 900000000) { 
  • 代替值使用获得optionset的标签功能getText(不建议,因为如果标签更改,例如在多语言环境中将不起作用)
if (Xrm.Page.getAttribute("new_mstatus").getText() =='Inactive') {