dynamic crm 前端动态获取实体的选项集
话不多说上代码
var requestUrl = Xrm.Utility.getGlobalContext().getClientUrl() +
"/api/data/v9.1/EntityDefinitions(LogicalName='实体名称')" +
"/Attributes(LogicalName='选项集字段名称')" +
"/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$expand=OptionSet";
fetch(requestUrl, {
method: "GET",
headers: {
"Accept": "application/json",
"Content-Type": "application/json; charset=utf-8",
"OData-MaxVersion": "4.0",
"OData-Version": "4.0"
}
}).then(response => response.json())
.then(data => {
if (data.OptionSet && data.OptionSet.Options) {
// 将选项集数据添加到数组以便后续使用
var Options = [];
data.OptionSet.Options.forEach(function (option) {
Options.push({
Label: option.Label.UserLocalizedLabel.Label,// 显示文本
value: option.Value // 值
})
console.log("Label: " + option.Label.UserLocalizedLabel.Label +
", Value: " + option.Value);
});
}
})
.catch(error => {
console.log("Error retrieving options: " + error.message);
});
data.OptionSet.Options的层级结构如下

前端动态获取Dynamic CRM选项集方法
373

被折叠的 条评论
为什么被折叠?



