- Create two fields to store optionset value and text
- Create html webresource with below source code.
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
ConvertDropDownToCheckBox();
});
//Coverts option list to checkbox
function ConvertDropDownToCheckBox() {
var _optionSet = parent.Xrm.Page.getAttribute("new_optionSet").getOptions();
var _optionSetValue = parent.Xrm.Page.getAttribute("address1_line1").getValue();
$(_optionSet).each(function (i, e) {
var _text = $(this)[0].text;
var _value = $(this)[0].value;
var _isChecked = false;
if (_text !== '') {
if (_optionSetValue !== null && _optionSetValue.indexOf(_value) !== -1)
_isChecked = true;
var _checkbox = "<input type='checkbox' name='" + _value + "'/>";
$(_checkbox)
.attr("value", _value)
.attr("checked", _isChecked)
.attr("id", "id" + _value)
.click(function () {
//To Set Picklist Select Values
var selectedOption = parent.Xrm.Page.getAttribute("address1_line1").getValue();
if (this.checked) {
if (selectedOption === null)
selectedOption = _value;
else {
var temp = selectedOption.indexOf(",") !== -1 ? selectedOption.split(',') : selectedOption.split(' ');
temp.push(_value);
selectedOption = temp.join();
}
}
else {
if (selectedOption.indexOf(_value) !== -1) {
var temp = selectedOption.indexOf(",") !== -1 ? selectedOption.split(',') : selectedOption.split(' ');
temp = removeArrayElement(temp, _value);
selectedOption = temp.join();
}
else
selectedOption = selectedOption.replace(_value, "");
}
parent.Xrm.Page.getAttribute("address1_line1").setValue(selectedOption.toString());
//To Set Picklist Select Text
var _selectedText = parent.Xrm.Page.getAttribute("address1_line2").getValue();
if (this.checked) {
if (_selectedText === null)
_selectedText = _text;
else {
var temp = _selectedText.indexOf(',') !== -1 ? _selectedText.split(',') : _selectedText.split(' ');
temp.push(_text);
_selectedText = temp.join();
}
}
else {
if (_selectedText.indexOf(_text) != -1) {
var temp = _selectedText.indexOf(',') !== -1 ? _selectedText.split(',') : _selectedText.split(' ');
temp = removeArrayElement(temp, _text);
_selectedText = temp.join();
}
else
_selectedText = _selectedText.replace(_text, "");
}
parent.Xrm.Page.getAttribute("address1_line2").setValue(_selectedText);
}).appendTo(checkBoxContainer);
}
//add label to the checkbox
$("<label for='" + _value + "'>" + _text + "</label>").appendTo(checkBoxContainer);
});
}
function removeArrayElement(arr) {
var what, a = arguments, L = a.length, ax;
while (L > 1 && arr.length) {
what = a[--L];
while ((ax = arr.indexOf(what.toString())) != -1) {
arr.splice(ax, 1);
}
}
return arr;
}
</script>
</head>
<body>
<div id="checkBoxContainer">
</div>
</body>
</html>
https://community.dynamics.com/crm/f/117/t/211615
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.