function GetOptionSetOptionValue(optionText, optionSetLogicalName)
{
debugger;
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/EntityDefinitions(LogicalName='ab_bid')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$filter=LogicalName eq '" + optionSetLogicalName + "' &$expand=OptionSet", 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.send(null);
if (req.readyState === 4) {
req.onreadystatechange = null;
if (req.status === 200) {
var results = JSON.parse(req.response);
debugger;
for (var i = 0; i < results.value[0].OptionSet.Options.length; i++) {
debugger;
var Label = results.value[0].OptionSet.Options[i].Label.UserLocalizedLabel.Label;
if (Label.trim().toLowerCase() == optionText.trim().toLowerCase()) {
return results.value[0].OptionSet.Options[i].Value;
}
//alert(Label);
}
} else {
Xrm.Utility.alertDialog(req.statusText);
}
}
}
{
debugger;
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/EntityDefinitions(LogicalName='ab_bid')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$filter=LogicalName eq '" + optionSetLogicalName + "' &$expand=OptionSet", 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.send(null);
if (req.readyState === 4) {
req.onreadystatechange = null;
if (req.status === 200) {
var results = JSON.parse(req.response);
debugger;
for (var i = 0; i < results.value[0].OptionSet.Options.length; i++) {
debugger;
var Label = results.value[0].OptionSet.Options[i].Label.UserLocalizedLabel.Label;
if (Label.trim().toLowerCase() == optionText.trim().toLowerCase()) {
return results.value[0].OptionSet.Options[i].Value;
}
//alert(Label);
}
} else {
Xrm.Utility.alertDialog(req.statusText);
}
}
}
No comments:
Post a Comment