Search code examples
htmldynamics-crm

how can i change the html code in crm form?


I used dynamics CRM 2015 and i want to change the OptionSet type to checkboxs. Just like this: enter image description here

My solution is use JQuery get the td tag in crm form,and use html() change the td html code. Like this $("#ubg_note_d").html().But question comes that i can't get the td tag which i want to display the checkbox.Only after i used the browser DEVELOPER TOOLS and select the element,then i can get the tag......i have blocked by this for 1 day,any helps?;)

note:i tried the js and jquery,both can't get the td tag.My code is run in the form Onload event,and i tried the filed Onchange event,trouble still there...


Solution

  • Thing you are trying to achieve is unsupported. Instead you can achieve the same using supported way by creating html web resource, which can be added on form on later.

    Code for web resource is as below.

    <html><head>
        <title></title>
        <script type="text/javascript" src="new_jquery_1.10.2.js"></script>
        <script type="text/javascript">
    
            // function will be called when web resource is loaded on Form.
            $(document).ready(function () {
                ConvertDropDownToCheckBoxList();
            });
    
            //Coverts option list to checkbox list.
            function ConvertDropDownToCheckBoxList() {
                var dropdownOptions = parent.Xrm.Page.getAttribute("new_makeyear").getOptions();
                var selectedValue = parent.Xrm.Page.getAttribute("new_selectedyears").getValue();
    
                $(dropdownOptions).each(function (i, e) {
                    var rText = $(this)[0].text;
                    var rvalue = $(this)[0].value;
                    var isChecked = false;
                    if (rText != '') {
                        if (selectedValue != null && selectedValue.indexOf(rvalue) != -1)
                            isChecked = true;
    
                        var checkbox = "< input type='checkbox' name='r' / >" + rText + ""
                        $(checkbox)
                            .attr("value", rvalue)
                            .attr("checked", isChecked)
                              .attr("id", "id" + rvalue)
                            .click(function () {
                                //To Set Picklist Select Values
                                var selectedOption = parent.Xrm.Page.getAttribute("new_selectedyears").getValue();
                                if (this.checked) {
                                    if (selectedOption == null)
                                        selectedOption = rvalue;
                                    else
                                        selectedOption = selectedOption + "," + rvalue
                                }
                                else {
                                    var tempSelected = rvalue + ",";
                                    if (selectedOption.indexOf(tempSelected) != -1)
                                        selectedOption = selectedOption.replace(tempSelected, "");
                                    else
                                        selectedOption = selectedOption.replace(rvalue, "");
                                }
                                parent.Xrm.Page.getAttribute("new_selectedyears").setValue(selectedOption);
    
    
                                //To Set Picklist Select Text
                                var selectedYear = parent.Xrm.Page.getAttribute("new_selectedyeartext").getValue();
                                if (this.checked) {
                                    if (selectedYear == null)
                                        selectedYear = rText;
                                    else
                                        selectedYear = selectedYear + "," + rText
                                }
                                else {
                                    var tempSelectedtext = rText + ",";
                                    if (selectedYear.indexOf(tempSelectedtext) != -1)
                                        selectedYear = selectedYear.replace(tempSelectedtext, "");
                                    else
                                        selectedYear = selectedYear.replace(rText, "");
                                }
                                parent.Xrm.Page.getAttribute("new_selectedyeartext").setValue(selectedYear);
    
                            })
                            .appendTo(checkboxList);
                    }
                });
            }
        </script> 
        <meta charset="utf-8">
    </head><body>
        <div id="checkboxList">
         
        </div>
    
    </body></html>

    Refer below given link for

    enter link description here