Requirement
Get OptionSet label based on the OptionSet values usingclient-side code.
Solution
Get OptionSet label based on the OptionSet values usingclient-side code.
Solution
We have several options to implement this requirement. Earlier, we wrote a post to get OptionSet label using formatted values. Today, we are going to discuss how we can use StringMap to get this OptionSet label using Web API. StringMap entity store gives details about optionsets. It has the following attributes.

Based on the above attributes, to get OptionSet label based on the values, we need to use the following three attributes.
We can use the following WebAPI request by passing the above parameters.
- function GetOptionSetLable(entityname, attributename, attributevalue) {
- //prepare query options
- var query = "/api/data/v8.2/stringmaps?$filter=objecttypecode eq '" + entity + "' and attributename eq '" + attributename + "' and attributevalue eq " + attributevalue;
- //setup webapi request
- var req = new XMLHttpRequest();
- req.open("GET", Xrm.Page.context.getClientUrl() + query, 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=\"*\"");
- req.onreadystatechange = function () {
- if (this.readyState === 4) {
- req.onreadystatechange = null;
- if (this.status === 200) {
- var results = JSON.parse(this.response);
- if (results != null && results.value.length > 0)
- Xrm.Utility.alertDialog(results.value[0].value);
- } else {
- Xrm.Utility.alertDialog(this.statusText);
- }
- }
- };
- req.send();
- }
I hope it will help someone!

Viknaraj ManogararajahPosted Jul 14, 2018, 11:10 PM
Nice Article, Thank you for sharing.........
Sanghamitra MohantyPosted Jul 7, 2018, 11:19 AM
its really good infomation.??
Ashish VishwakarmaPosted Jul 7, 2018, 5:19 AM
Awesome information sir, I thought StringMap is only for on-premises