以下是原始代码示例:
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属性不再起作用。
我尝试过这个样本:
function 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
是否有任何想法或主角让它发挥作用?
答案 0 :(得分: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-upgrade.aspx
答案 1 :(得分:0)
您可以获得在crm表单上创建按钮的高效代码。它适用于CRM 2011和CRM 2013.
http://crmjavascripts.blogspot.in/2013/12/add-button-on-crm-2013-form.html