0

这是原始代码示例:

function create_button_from_textattribute(fieldname, buttontext, buttonwidth, clickevent) {
    functiontocall = clickevent;
    crmForm.all[fieldname].DataValue = buttontext;
    crmForm.all[fieldname].readOnly = true;
    crmForm.all[fieldname].style.borderRight = "#3366cc 1px solid";
    crmForm.all[fieldname].style.paddingRight = "5px";
    crmForm.all[fieldname].style.borderTop = "#3366cc 1px solid";
    crmForm.all[fieldname].style.paddingLeft = "5px";
    crmForm.all[fieldname].style.fontSize = "11px";
    crmForm.all[fieldname].style.backgroundImage = "url(/_imgs/btn_rest.gif)";
    crmForm.all[fieldname].style.borderLeft = "#3366cc 1px solid";
    crmForm.all[fieldname].style.width = buttonwidth;
    crmForm.all[fieldname].style.cursor = "hand";
    crmForm.all[fieldname].style.lineHeight = "18px";
    crmForm.all[fieldname].style.borderBottom = "#3366cc 1px solid";
    crmForm.all[fieldname].style.backgroundRepeat = "repeat-x";
    crmForm.all[fieldname].style.fontFamily = "Tahoma";
    crmForm.all[fieldname].style.height = "20px";
    crmForm.all[fieldname].style.backgroundColor = "#cee7ff";
    crmForm.all[fieldname].style.textAlign = "center";
    crmForm.all[fieldname].style.overflow = "hidden";
    crmForm.all[fieldname].attachEvent("onmousedown", push_button);
    crmForm.all[fieldname].attachEvent("onmouseup", release_button);
    crmForm.all[fieldname].attachEvent("onclick", functiontocall);
}

在 Dynamics Crm 2013 中迁移后,readOnly 和 DataValue 属性不再起作用。

我已经尝试过使用此示例的方法:

函数 create_button_from_textattribute(fieldname, buttontext, buttonwidth, clickevent) {

   var btn = '<button id="btn_' + fieldname + '" ' + 
                    ' style="width:' + buttonwidth + '" ' + 
                    ' class="ms-crm-Button" ' + 
                    ' onmouseover="Mscrm.ButtonUtils.hoverOn(this);" ' + 
                    ' onmouseout="Mscrm.ButtonUtils.hoverOff(this);" ' +
                '>' + buttontext + '</button>';

 var ctrl = Xrm.Page.ui.controls.get(fieldname)._control;
 ctrl.get_element().innerHTML += btn;
 ctrl.get_element().firstChild.style.display = 'none';

 Xrm.Page.ui.controls.get('new_btnmaj').setLabel('');
 ctrl.get_element().childNodes[1].attachEvent('onclick', clickevent);

但是我收到 Xrm.Page.ui.controls.get(fieldname)._control 行的未定义元素错误

有什么想法或线索可以让它发挥作用吗?

4

2 回答 2

2

我希望您知道 CRM 表单不支持 DOM 中的更改。

可以通过“Xrm.Page.data.entity 属性方法”来设置属性的值(请参阅http://msdn.microsoft.com/en-us/library/gg334409.aspx)设置属性只读可以是由“Xrm.Page.ui 控制方法”完成(参见http://msdn.microsoft.com/en-us/library/gg334266.aspx

有关 CRM 2011 和 CRM 2013 之间更改的更多信息,请参阅:http: //blogs.msdn.com/b/crm/archive/2013/08/23/check-your-javascript-code-to-prepare-for-your -升级.aspx

于 2013-11-07T10:42:29.970 回答
0

您可以获得在 crm 表单上制作按钮的有效代码。它适用于 CRM 2011 和 CRM 2013。

http://crmjavascripts.blogspot.in/2013/12/add-button-on-crm-2013-form.html

于 2013-12-22T16:44:43.433 回答