Reputation: 569
Here is the original code sample :
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);
}
After the migration in Dynamics Crm 2013, the readOnly and DataValue properties don't work anymore.
I've tried a way around with this sample :
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);
But I get an undefined element error for the line Xrm.Page.ui.controls.get(fieldname)._control
Any idea or lead bout the way to make it work?
Upvotes: 0
Views: 2264
Reputation: 1
You can get efficient code for making a button on crm form. It works on both CRM 2011 as well as CRM 2013.
http://crmjavascripts.blogspot.in/2013/12/add-button-on-crm-2013-form.html
Upvotes: 0
Reputation: 111
I hope you know that changes in the DOM are not supported on CRM forms.
Setting the value of an attribute can be done by the 'Xrm.Page.data.entity Attribute Methods' (see http://msdn.microsoft.com/en-us/library/gg334409.aspx) Setting a attribute readonly can be done by the 'Xrm.Page.ui Control Methods' (see http://msdn.microsoft.com/en-us/library/gg334266.aspx)
For more information about changes between CRM 2011 and CRM 2013 see : http://blogs.msdn.com/b/crm/archive/2013/08/23/check-your-javascript-code-to-prepare-for-your-upgrade.aspx
Upvotes: 2