Create Button in CRM Form without a Field using Javascript
///http://missdynamicscrm.blogspot.in/2015/06/create-button-in-crm-form-javascript.html
function btncal() {
createButton(id, defaultText, intWidth, onClickEventFunctionName);
}
function createButton(id, defaultText, intWidth, onClickEventFunctionName) {
debugger;
var btn = document.createElement("BUTTON");
// Create a <button> element, you can also use input,but need to set type to button
var t = document.createTextNode(defaultText);
btn.appendChild(t);
btn.className = "ms-crm-Button";
btn.id = id;
if (intWidth != null) {
btn.style.width = intWidth + "px";
}
else {
//defaulted width
btn.style.width = "100%";
}
btn.onmouseover = onCRMBtnMouseHover;
btn.onmouseout = onCRMBtnMouseOut;
btn.onclick = onClickEventFunctionName;
return btn;
}
//use this for creating a button with hovering style like CRM has
function onCRMBtnMouseHover() {
Mscrm.ButtonUtils.hoverOn(this);
}
function onCRMBtnMouseOut() {
Mscrm.ButtonUtils.hoverOff(this)
}
function createButtonCalculate() {
//debugger;
var btnTemplate = createButton("btnCalculateCourseFeePerHour", "Calculate", 100, btnCalculate_onClick);
//put this code if you want to insert the button just after a field,
var insertAfterField = parent.document.getElementById('new_abcal');
insertAfterField.parentElement.insertBefore(btnTemplate, insertAfterField.nextSibling);
//if you want to put after a grid, section, or another element it is possible also/
//remember it is using DOM method
//if you want to put before an element, just use this (without nextSibling
//insertAfterField.parentElement.insertBefore(btnTemplate, insertAfterField);
}
function btnCalculate_onClick() {
//put your logic here
var a = Xrm.Page.getAttribute("new_a").getValue();
var b = Xrm.Page.getAttribute("new_b").getValue();
var ab = a + b;
Xrm.Page.getAttribute("new_abcal").setValue(ab);
alert("clicked!");
}
function btncal() {
createButton(id, defaultText, intWidth, onClickEventFunctionName);
}
function createButton(id, defaultText, intWidth, onClickEventFunctionName) {
debugger;
var btn = document.createElement("BUTTON");
// Create a <button> element, you can also use input,but need to set type to button
var t = document.createTextNode(defaultText);
btn.appendChild(t);
btn.className = "ms-crm-Button";
btn.id = id;
if (intWidth != null) {
btn.style.width = intWidth + "px";
}
else {
//defaulted width
btn.style.width = "100%";
}
btn.onmouseover = onCRMBtnMouseHover;
btn.onmouseout = onCRMBtnMouseOut;
btn.onclick = onClickEventFunctionName;
return btn;
}
//use this for creating a button with hovering style like CRM has
function onCRMBtnMouseHover() {
Mscrm.ButtonUtils.hoverOn(this);
}
function onCRMBtnMouseOut() {
Mscrm.ButtonUtils.hoverOff(this)
}
function createButtonCalculate() {
//debugger;
var btnTemplate = createButton("btnCalculateCourseFeePerHour", "Calculate", 100, btnCalculate_onClick);
//put this code if you want to insert the button just after a field,
var insertAfterField = parent.document.getElementById('new_abcal');
insertAfterField.parentElement.insertBefore(btnTemplate, insertAfterField.nextSibling);
//if you want to put after a grid, section, or another element it is possible also/
//remember it is using DOM method
//if you want to put before an element, just use this (without nextSibling
//insertAfterField.parentElement.insertBefore(btnTemplate, insertAfterField);
}
function btnCalculate_onClick() {
//put your logic here
var a = Xrm.Page.getAttribute("new_a").getValue();
var b = Xrm.Page.getAttribute("new_b").getValue();
var ab = a + b;
Xrm.Page.getAttribute("new_abcal").setValue(ab);
alert("clicked!");
}
Comments
Post a Comment