这是原始代码示例:
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 行的未定义元素错误
有什么想法或线索可以让它发挥作用吗?