locked
How to Convert Option Set in to a Check Box list in mscrm2013? RRS feed

  • Question

  • Hi All,

    I am using this code for "Convert Option Set in to a Check Box list" but not working in MSCRM2013 please help me out .

    function Form_onload() {

        var optionset = document.getElementById("new_optionset");
        var multiline = document.getElementById("new_multilinetext");

        if (optionset != null && multiline != null) {

            optionset.style.display = "none";            //"none" represents override of existing, the optionset field is overrided
            var pdiv = document.createElement('div');    //Create an element
            pdiv.style = 'overflow-y:auto; height:100px; border:2px #6699cc solid; background-color:#ffffff;'; 
            //overflow y represents vertical scroll bar for options if options are more which will display if options are more.

            optionset.parentNode.appendChild(pdiv);

    // Convert option set to check box

            for (var i = 1; i < optionset.options.length; i++) {
                var OptionSetItems = optionset.options[i];
                if (!IsChecked(OptionSetItems.text, multiline)) {
                    var addInput = document.createElement('input');
                    addInput.type = 'checkbox';
                    addInput.style.pixelWidth = 30;
                }
                else {
                    var addInput = document.createElement('input');
                    addInput.type = 'checkbox';
                    addInput.checked = true;
                    addInput.style.pixelWidth = 30;
                }

                var addLabel = document.createElement('label');
                addLabel.innerText = OptionSetItems.text;
                var addBr = document.createElement('br');
             
                optionset.nextSibling.appendChild(addInput);
                optionset.nextSibling.appendChild(addLabel);
                optionset.nextSibling.appendChild(addBr);

            }
        }
    }

    // To check if which check box is selected
    function IsChecked(pText, multiline) {
        if (multiline.value != "") {
            var multiline = multiline.value.split(",");
            for (var i = 0; i <multiline.length; i++) {
                if (multiline[i] == pText)
                    return true;
            }
        }
        return false;
    }

    function Form_onSave() {
      
        var optionset = document.getElementById("new_optionset");
      
        var multiline = "";
        var getInput = optionset.nextSibling.getElementsByTagName("input");

        for (var i = 0; i < getInput.length; i++) {
            if (getInput[i].checked) {
                multiline += getInput[i].nextSibling.innerText + ",";
    //placing all the options into multiline of text
            }
        }
        Xrm.Page.getAttribute("new_multilinetext").setValue(multiline);

    }

    Thanking in advance.

    Regards,

    Surya

    Tuesday, April 29, 2014 5:19 AM