Hi All,
As we know Microsoft has announced their new version of Microsoft Dynamics CRM  known as CRM 2013 (Orion), So while migrating to the new version I faced some issues related to javascript.
1 of the key requirement in the CRM project was to migrate the multi checkbox list in CRM 2013. When I tried to open the same record in CRM 2013 with multicheckbox control implemented, I got many errors because of javascript like “Unable to find the property” bla bla…

So I tried to correct to javascript code in order to run the same functionality in CRM 2013 also.
So here is the JS code where you will find the slight changes in the javascript:
//This function is for OnLoad
//fieldName==> ‘new_fieldname’
//Create a multitext field with same name + suffix as ‘_value’ to store the values and hide it
function CheckBox_OnLoad(fieldName) {
var optionset = “”;
var optionsetvalue = “”;
var OS1 = “”;
var OSV2 = “”;
var OS = “”;
var OSV = “”;
var oAttributes = Xrm.Page.data.entity.attributes.get(fieldName);
optionset = oAttributes.getName();
optionsetvalue = oAttributes.getName() + “_value”;
OS = document.getElementById(optionset);
if (Xrm.Page.getControl(optionsetvalue) != null || Xrm.Page.getControl(optionsetvalue) != undefined) {
Xrm.Page.getControl(optionsetvalue).setVisible(true);
} //end of if
OSV = document.getElementById(optionsetvalue);
if (OS != null) {
if (OSV != null) {
ConvertToMultiCheckbox(optionset, optionsetvalue, OS, OSV);
if (Xrm.Page.getControl(optionsetvalue) != null || Xrm.Page.getControl(optionsetvalue) != undefined) {
Xrm.Page.getControl(optionsetvalue).setVisible(false); 
document.getElementById(optionset + “_c”).style.display = ‘Inline’;
//document.getElementById(optionsetvalue + “_d”).style.display = ‘none’;
} //end of if
} //end of if
} //end of if
}
function ConvertToMultiCheckbox(var_new_optionset, var_new_optionsetvalue, OS, OSV) {
if (OS != null && OSV != null) {
Xrm.Page.getControl(var_new_optionsetvalue).setVisible(false);
//Create the div container for the checkbox list
var divid = “div_” + var_new_optionset;
var DivElement = “<div id=’” + divid + “‘ title=’” + var_new_optionset + “‘ style=’overflow-y:auto; height:120px; border:1px #6699cc solid; background-color:#ffffff; padding-right:10px; padding-left:10px; ‘ />”
var DivExist = document.getElementById(divid);
if (DivExist != null || DivExist != undefined) {
var div = document.getElementById(divid);
div.parentNode.removeChild(div);
CreateDiv(var_new_optionset, var_new_optionsetvalue, OS, OSV, DivElement, divid)
}
else {
CreateDiv(var_new_optionset, var_new_optionsetvalue, OS, OSV, DivElement, divid)
}
}
}
function CreateDiv(var_new_optionset, var_new_optionsetvalue, OS, OSV, DivElement, divid) {
// Create a DIV container
try {
var addDiv = document.createElement(DivElement);
} //end of try
catch (e) {
var addDiv = document.createElement(“div”);
addDiv.setAttribute(“id”, divid);
addDiv.setAttribute(“title”, var_new_optionset);
addDiv.setAttribute(“style”, “overflow-y:auto; height:120px; border:1px #6699CC solid; background-color:#F6F8FA; padding-right:10px; padding-left:10px; “);
} //end of catch
OS.parentNode.appendChild(addDiv);
// Initialise multi checkbox controls
var OSO = Xrm.Page.getAttribute(var_new_optionset);
var options = OSO.getOptions();
for (var i in options) {
var pOption = options[i];
try {
var OSVText = Xrm.Page.getAttribute(var_new_optionsetvalue).getValue();
var isChecboxChecked = IsChecked(pOption.text, OS, OSVText);
if (isChecboxChecked == true && pOption.text != “”) {
var addInput = document.createElement(“<input type=’checkbox’ checked=’checked’ style=’border:none; width:25px; align:left;’ />”);
}
else if (pOption.text != “”) {
var addInput = document.createElement(“<input type=’checkbox’ style=’border:none; width:25px; align:left;’ />”);
} //end of if
} //end of try
catch (e) {
var OSVText = Xrm.Page.getAttribute(var_new_optionsetvalue).getValue();
var isChecboxChecked = IsChecked(pOption.text, OS, OSVText);
if (isChecboxChecked == true && pOption.text != “”) {
var addInput = document.createElement(“input”);
addInput.setAttribute(“type”, “checkbox”);
addInput.setAttribute(“checked”, “checked”);
addInput.setAttribute(“style”, “border:none; width:25px; align:left;”);
}
//end of if
else if (pOption.text != “”) {
var addInput = document.createElement(“input”);
addInput.setAttribute(“type”, “checkbox”);
addInput.setAttribute(“style”, “border:none; width:25px; align:left;”);
}
var addLabel = document.createElement(“label”);
var pOptionValue = pOption.value;
addLabel.innerText = pOption.text;
var addBr = document.createElement(“br”); //it’s a ‘br’ flag
OS.nextSibling.appendChild(addInput);
OS.nextSibling.appendChild(addLabel);
OS.nextSibling.appendChild(addBr);
} //end of catch
Xrm.Page.getControl(var_new_optionset).setVisible(true);
Xrm.Page.getControl(var_new_optionset).setVisible(false);
} //end of for
}
function IsChecked(pValue, OS, OSV) {
var result = false;
if (OSV != “” && OSV != null) {
var OSVT = OSV.split(“;”);
for (var i = 0; i < OSVT.length; i++) {
if (OSVT[i] == pValue && OSVT[i] != “”) {
result = true;
break;
}
else
{ result = false; }
}
}
return result;
}
//This function is for Onsave
function Multiselect_OnSave(fieldName) {
var optionset = “”;
var optionsetvalue = “”;
var OS = “”;
var OSV = “”;
var oAttributes = Xrm.Page.data.entity.attributes.get(fieldName);
optionset = oAttributes.getName();
optionsetvalue = oAttributes.getName() + “_value”;
OS = document.getElementById(optionset);
OSV = document.getElementById(optionsetvalue);
if (OS != null) {
if (OSV != null) {
executeOnSave(OS, optionsetvalue);
}
}
}
function executeOnSave(OS, var_new_optionsetvalue) {
var getInput = OS.nextSibling.getElementsByTagName(“input”);
var result = ”;
for (var i = 0; i < getInput.length; i++) {
if (getInput[i].checked) {
result += getInput[i].nextSibling.innerText + “;”;
}
}
//save value
control = Xrm.Page.getControl(var_new_optionsetvalue);
attribute = control.getAttribute();
attribute.setValue(result);
}
Multicheckbox
In this way, you will be able to implement the multicheckbox control in CRM 2013 version.


SOURCE : JUST2CODE.IN
Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012