{"id":3038,"date":"2018-06-30T00:00:47","date_gmt":"2018-06-30T00:00:47","guid":{"rendered":"http:\/\/himbap.com\/blog\/?p=3038"},"modified":"2018-08-18T08:17:01","modified_gmt":"2018-08-18T08:17:01","slug":"get-optionset-label-using-stringmap-web-api","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=3038","title":{"rendered":"Get Optionset Label using stringmap- Web API"},"content":{"rendered":"<p><strong>Requirement<\/strong>: Get Optionset label based on optionset value using client side code.<br \/>\n<strong>Solution<\/strong>: We have different option to implement this requirement. Earlier we wrote a post to get option set label using <a href=\"https:\/\/himbap.com\/blog\/?p=2077\">formatted values<\/a>, today we are going to discuss how we can use stringmap to get optionset label using Web API. Stringmap entity store details about optionsets, it has following attributes:<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/06\/stringmap.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-3040 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/06\/stringmap-300x151.png\" alt=\"stringmap\" width=\"300\" height=\"151\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/06\/stringmap-300x151.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/06\/stringmap.png 395w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nBased on above attributes, to get optionset label based on the value we need to use three following attributes:<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/06\/stringmap1.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-3039 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/06\/stringmap1-300x49.png\" alt=\"stringmap1\" width=\"300\" height=\"49\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/06\/stringmap1-300x49.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/06\/stringmap1-624x102.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2018\/06\/stringmap1.png 638w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>We can use following WebAPI request by passing above parameters:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction GetOptionSetLable(entityname, attributename, attributevalue) {\r\n    \/\/prepare query options\r\n    var query = &quot;\/api\/data\/v8.2\/stringmaps?$filter=objecttypecode eq '&quot; + entityname + &quot;' and  attributename eq '&quot; + attributename + &quot;' and attributevalue eq &quot; + attributevalue;\r\n    \/\/setup webapi request\r\n    var req = new XMLHttpRequest();\r\n    req.open(&quot;GET&quot;, Xrm.Page.context.getClientUrl() + query, false);\r\n    req.setRequestHeader(&quot;OData-MaxVersion&quot;, &quot;4.0&quot;);\r\n    req.setRequestHeader(&quot;OData-Version&quot;, &quot;4.0&quot;);\r\n    req.setRequestHeader(&quot;Accept&quot;, &quot;application\/json&quot;);\r\n    req.setRequestHeader(&quot;Content-Type&quot;, &quot;application\/json; charset=utf-8&quot;);\r\n    req.setRequestHeader(&quot;Prefer&quot;, &quot;odata.include-annotations=\\&quot;*\\&quot;&quot;);\r\n    req.onreadystatechange = function () {\r\n        if (this.readyState === 4) {\r\n            req.onreadystatechange = null;\r\n            if (this.status === 200) {\r\n                var results = JSON.parse(this.response);\r\n                if (results != null &amp;&amp; results.value.length &gt; 0)\r\n                    Xrm.Utility.alertDialog(results.value[0].value);\r\n\r\n            } else {\r\n                Xrm.Utility.alertDialog(this.statusText);\r\n            }\r\n        }\r\n    };\r\n    req.send();\r\n}\r\n<\/pre>\n<p>Hope it will help someone !!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Requirement: Get Optionset label based on optionset value using client side code. Solution: We have different option to implement this requirement. Earlier we wrote a post to get option set label using formatted values, today we are going to discuss how we can use stringmap to get optionset label using Web API. Stringmap entity store details about optionsets, it has&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=3038\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":3036,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[402,522,296],"tags":[529,526,528,530],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3038"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3038"}],"version-history":[{"count":6,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3038\/revisions"}],"predecessor-version":[{"id":4360,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3038\/revisions\/4360"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/3036"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3038"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3038"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3038"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}