我正在使用D-CRM 2016,我试图在客户端(js)中获得选项集的标签,但出现错误,找不到原因: 那就是我的代码:
SDK.Metadata.RetrieveAttribute("myEntity", "myFieldName", null, false,
function (result) {
alert(result);
for (var i = 0; i < result.OptionSet.Options.length; i++) {
var loopText = result.OptionSet.Options[i].Label.LocalizedLabels[0].Label;
var loopValue = result.OptionSet.Options[i].Value;
}
},
function (error) { }
,false);
我的错误:
Uncaught TypeError: _Context(...).getServerUrl is not a function
at _getUrl (/SDev/%7B636656731400000359%7D/WebResources/xnes_SDK.MetaData?ver=1561501807:451)
at Object.RetrieveAttribute (/SDev/%7B636656731400000359%7D/WebResources/xnes_SDK.MetaData?ver=1561501807:323)
at <anonymous>:1:14
at Mscrm.CommandHandler.$Ce_1 (JsProvider.ashx:8)
at Mscrm.CommandHandler.$Ag_1 (JsProvider.ashx:8)
at Mscrm.CommandHandler.handleCommand (JsProvider.ashx:8)
at Mscrm.CommandBarData.executeCommand (JsProvider.ashx:8)
at Mscrm.ButtonControl.executeCommand (ribbon.js:1)
at Mscrm.ButtonControl.click (ribbon.js:1)
at Mscrm.CommandBar.onClickHandler (ribbon.js:1)
答案 0 :(得分:0)
无论何时您尝试进行客户端休息呼叫,我总是建议使用Jason Lattimer的CRM Rest Builder(https://github.com/jlattimer/CRMRESTBuilder)。您可以使用“格式化的值”选项访问文本标签。
答案 1 :(得分:0)
主要问题是使用的SDK。我真的不能为您调试它。
但是,这里有一个工作示例正在返回标签和值。您可以添加标头(首选),以告诉api也返回标签:
var odataEndPoint = Xrm.Page.context.getClientUrl() + '/api/data/v8.2/';
function GetDomainName(entityId) {
var result = null;
var req = new XMLHttpRequest();
req.open("GET", odataEndPoint + 'systemusers(' + TrimGuid(entityId) + ')/', false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
req.onreadystatechange = function () {
if (this.readyState == 4) {
req.onreadystatechange = null;
if (this.status == 200) {
if (this.response) {
result = JSON.parse(this.response);
}
}
else {
var parsed = JSON.parse(this.response);
console.error(parsed.error.message)
}
}
};
req.send();
return result;
};