Hi All,
I am
using CRM 2016, the below function are not working in crm 2016, which were working
in the CRM 2015.
In a script i am using "nextsibling" , onsave of the form it is throwing an error("Unable
to get property 'nextSibling' of undefined or null reference").Can anyone help me on this.
I'm using the below code.
// var_sc_optionset >> Provide schema-name for Option Set field
// var_sc_optionsetvalue >> Provide schema-name for field which will store the multi selected values for Option
Set
// OS >> Provide Option Set field object
// OSV >> Provide text field object which will store the multi selected values for Option Set
//Method to convert an optionset to multi select Option Set
// OS == parent.window.document.getElementById('new_productcategory'),"new_productcategoryvalue"
function ConvertToMultiSelect(var_sc_optionset, var_sc_optionsetvalue, OS, OSV) {
// debugger;
if (OS != null && OSV != null) {
OS.style.display = "none";
Xrm.Page.getControl(var_sc_optionsetvalue).setVisible(false);
// Create a DIV container
var addDiv = document.createElement("div");
addDiv.setAttribute("style", "overflow-y:auto; height:200px; border:1px #6699cc
solid; background-color:#ffffff;");
OS.parentNode.appendChild(addDiv);
// alert(OS.attributes.length);
// Initialise checkbox controls
if (OS != null) {
var options = OS.getElementsByTagName("option");
for (var i = 1; i < options.length; i++) {
var pOption = options[i];
var addInput = document.createElement("input");
addInput.setAttribute("type", "checkbox");
addInput.setAttribute("style", "border:none;
width:25px; align:left;");
if (IsChecked(pOption.text, OS, OSV)) {
addInput.setAttribute("checked", "checked");
}
var addLabel = document.createElement("label");
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);
}
// alert(OS.nextSibling.getElementsByTagName("input").length);
}
}
}
///////Supported functions
// Check if it is selected
function IsChecked(pText, OS, OSV) {
//debugger;
if (OSV.outerText != "--") {
//alert(OSV.value);
var OSVT = OSV.outerText.split(";");
for (var i = 0; i < OSVT.length; i++) {
if (OSVT[i] == pText)
return true;
}
}
return false;
}
// var_sc_optionsetvalue >> Provide schema-name for field which will store the multi selected values for Option
Set
// OS >> Provide Option Set field object
// Save the selected text, this field can also be used in Advanced Find
function OnSave(OS, var_sc_optionsetvalue) {
// debugger;
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_sc_optionsetvalue);
attribute = control.getAttribute();
attribute.setValue(result);
}
Regards,
Staya