Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Get OptionSet Label Using StringMap Web API
WhatsApp
Mahender Pal
6y
17.1k
0
3
100
Article
Requirement
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!
Dynamics 365 CE
Get option set label using Web API
Web API
Up Next
Ebook Download
View all
Printing in C# Made Easy
Read by 22.4k people
Download Now!
Learn
View all
HIMBAP
We are expert in Microsoft Power Platform.
Membership not found