The following javascript web resource is for fire event when check box clicked or checked in CRM 2011.
We can get immediate response when CRM check box is Checked or Unchecked.
Here is the example for Auto Populate Multi-line text field from check box selections.
Here three check boxes are available. When click on first check box, The text "First option is true" will populate in custom multiline textbox field. As well as click on the second check box, The text "second option is true" will populate in custom multiline textbox field without overwrite data.
This information has to populate the text box instantly so the user can make changes BEFORE saving the record .
function CheckOptionOnload()
{
RegisterCheckBoxOnclick();
}
function RegisterCheckBoxOnclick()
{
registerCheckboxClick("new_firstoption");
registerCheckboxClick("new_secondoption");
registerCheckboxClick("new_thirdoption");
}
function CheckOption()
{
var myAttribute1 = "new_firstoption";
var myControl1 = Xrm.Page.ui.controls.get(myAttribute1);
var myCheckboxValue1 = myControl1.getAttribute().getValue();
var myAttribute2 = "new_secondoption";
var myControl2 = Xrm.Page.ui.controls.get(myAttribute2);
var myCheckboxValue2 = myControl2.getAttribute().getValue();
var myAttribute3 = "new_thirdoption";
var myControl3 = Xrm.Page.ui.controls.get(myAttribute3);
var myCheckboxValue3 = myControl3.getAttribute().getValue();
if(myCheckboxValue1 ==false && myCheckboxValue2 ==false && myCheckboxValue3 ==false)
{
Xrm.Page.getAttribute("new_description").setValue(null);
}
else
{
var data="";
if (myCheckboxValue1 == true)
{
data=data+ "First Option is true \n";
Xrm.Page.getAttribute("new_description").setValue(data);
}
if (myCheckboxValue2 == true)
{
data=data+ "Second Option is true \n";
Xrm.Page.getAttribute("new_description").setValue(data);
}
if (myCheckboxValue3 == true)
{
data=data+ "Third Option is true \n";
Xrm.Page.getAttribute("new_description").setValue(data);
}
}
}
function registerCheckboxClick(attr) {
//var attr="new_firstoption";
var ctrl = Xrm.Page.ui.controls.get(attr);
var a = ctrl.getAttribute();
var el = document.getElementById(attr);
// Build Toggle Function
var f = "var ef=function() { " +
"var a = Xrm.Page.data.entity.attributes.get(attr); " +
"a.setValue(!a.getValue()); a.fireOnChange();" +
" };";
eval(f);
// Attach to click event
el.attachEvent('onclick', ef, false);
}
Here events and functions are
Onload : CheckOptionOnload
Onchange : CheckOption
We can get immediate response when CRM check box is Checked or Unchecked.
Here is the example for Auto Populate Multi-line text field from check box selections.
Here three check boxes are available. When click on first check box, The text "First option is true" will populate in custom multiline textbox field. As well as click on the second check box, The text "second option is true" will populate in custom multiline textbox field without overwrite data.
This information has to populate the text box instantly so the user can make changes BEFORE saving the record .
function CheckOptionOnload()
{
RegisterCheckBoxOnclick();
}
function RegisterCheckBoxOnclick()
{
registerCheckboxClick("new_firstoption");
registerCheckboxClick("new_secondoption");
registerCheckboxClick("new_thirdoption");
}
function CheckOption()
{
var myAttribute1 = "new_firstoption";
var myControl1 = Xrm.Page.ui.controls.get(myAttribute1);
var myCheckboxValue1 = myControl1.getAttribute().getValue();
var myAttribute2 = "new_secondoption";
var myControl2 = Xrm.Page.ui.controls.get(myAttribute2);
var myCheckboxValue2 = myControl2.getAttribute().getValue();
var myAttribute3 = "new_thirdoption";
var myControl3 = Xrm.Page.ui.controls.get(myAttribute3);
var myCheckboxValue3 = myControl3.getAttribute().getValue();
if(myCheckboxValue1 ==false && myCheckboxValue2 ==false && myCheckboxValue3 ==false)
{
Xrm.Page.getAttribute("new_description").setValue(null);
}
else
{
var data="";
if (myCheckboxValue1 == true)
{
data=data+ "First Option is true \n";
Xrm.Page.getAttribute("new_description").setValue(data);
}
if (myCheckboxValue2 == true)
{
data=data+ "Second Option is true \n";
Xrm.Page.getAttribute("new_description").setValue(data);
}
if (myCheckboxValue3 == true)
{
data=data+ "Third Option is true \n";
Xrm.Page.getAttribute("new_description").setValue(data);
}
}
}
function registerCheckboxClick(attr) {
//var attr="new_firstoption";
var ctrl = Xrm.Page.ui.controls.get(attr);
var a = ctrl.getAttribute();
var el = document.getElementById(attr);
// Build Toggle Function
var f = "var ef=function() { " +
"var a = Xrm.Page.data.entity.attributes.get(attr); " +
"a.setValue(!a.getValue()); a.fireOnChange();" +
" };";
eval(f);
// Attach to click event
el.attachEvent('onclick', ef, false);
}
Here events and functions are
Onload : CheckOptionOnload
Onchange : CheckOption
No comments:
Post a Comment