MultiSelect OptionSet

Using MultiSelect Option Set field, we can specify and select multiple values up to 150. This seems like an amazing feature of V9.0. Let’s find out good or bad of it. 🙂

Benefits:
1.Can add up to 150 values available for selection
2.Supported in Advanced Find & Fetch XML queries.
3.Can be used for filtering in views.

Limitations:
1.Can’t be used in Business Rules.
2.Can’t be used in BPF
3.Can’t be used in Workflow
4.Can’t be used as Plugin Filtering Attribute
5.Some Data migration tools doesn’t support MSOS.
6.Can’t be used in calculated & roll up fields.

Set Value Of MultiSelect OptionSet Field
function setFieldValue() {
var picklist = [1, 3];
Xrm.Page.getAttribute(“new_qualification”).setValue(picklist);
}

Get Value from MultiSelect OptionSet Field
function showValue() {
var picklist = Xrm.Page.getAttribute(“new_qualification”).getValue();
alert(picklist);
}
// Output: 1,3

Get Text Value from MultiSelect OptionSet Field
function showText() {
var picklist = Xrm.Page.getAttribute(“new_qualification”).getText();
alert(picklist);
}
//Output: B.Tech,M.Tech

Retrieve Value Of MultiSelect OptionSet Field using web api
function fetchAccountData() {
var EntityName = “account”;
var accid = Xrm.Page.getAttribute(“parentcustomerid”).getValue();
if (accid != null) {
var id = accid[0].id;
var guid = id.replace(‘{‘, ”).replace(‘}’, ”);
var url = window.parent.Xrm.Page.context.getClientUrl() + “/api/data/v8.0/” + EntityName + “s(” + guid + “)?$filter= statecode eq 0”;
var req = new XMLHttpRequest();
req.open(“GET”, url, false);
req.setRequestHeader(“OData-MaxVersion”, “4.0”);
req.setRequestHeader(“OData-Version”, “4.0”);
req.setRequestHeader(“Accept”, “application/json”);
req.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
req.setRequestHeader(“Prefer”, “odata.include-annotations=\”OData.Community.Display.V1.FormattedValue\””);
req.send();
if (req.status == 200)
{
var result = JSON.parse(req.response);
if (result != null && result != undefined)
{
alert(result.new_qualification);
// Output: “1,3”
alert(result[“new_qualification@OData.Community.Display.V1.FormattedValue”]);
// Output: “B.Tech; M.Tech”
for (var i = 0; i < result.new_qualification.split(“,”).length; i++)
{
result[“new_qualification@OData.Community.Display.V1.FormattedValue”].split(“;”)[i];
}
// “B.Tech”
// “M.Tech”
}
}
else
alert(“Error”);
}
}

Keep Learning!! Keep Exploring!!

Leave a Reply

Your email address will not be published. Required fields are marked *