Hi Everyone,
Today I got a requirement to retrieve Optionset Metadata using JavaScript.
Here is the code for the same.
function getOptionSetMetadata(schemaName) {
var schemaName = "industrycode"; // You can pass this as a parameter to this function and comment this line.
var optionSetFetch = `<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='stringmap' >
<attribute name='attributevalue' />
<attribute name='value' />
<filter type='and' >
<condition attribute='attributename' operator='eq' value= '${schemaName}' />
</filter>
</entity>
</fetch>`;
optionSetFetch = "?fetchXml=" + encodeURIComponent(optionSetFetch);
Xrm.WebApi.retrieveMultipleRecords("stringmap", optionSetFetch).then(
function success(result) {
if (result.entities.length > 0) {
console.log(result.entities);
for (count = 0; count < result.entities.length; count++) {
console.log("Attribute Value : " + result.entities[count].attributevalue);
console.log("Value : " + result.entities[count].value);
}
}
},
function (error) {
console.log(error.message);
});
}
Here is the output
Hope this helps.
—
Happy 365’ing
Gopinath.
*This post is locked for comments