使用 savedQuery 时有没有办法应用过滤器?例如,如果保存/预定义的视图返回多个帐户,例如使用以下 URL “.../api/data/v9.0/accounts?savedQuery=9e3ddee9-9e74-e811-a95d-000d3a34afa9”,是否存在一种为单个帐户返回相同保存视图的结果的方法?
问问题
582 次
1 回答
1
您可以将获取 XML 发送到 Web API。只需通过 Advanced Find 下载视图的 fetch XML。这是javascript中的一个示例:
var accountFetchXML = ['< fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">' +
'< entity name="account">' +
'< attribute name="name" />' +
'< filter type="and">' +
'< condition attribute="industrycode" operator="not-null" />' +
'</ filter>' +
'< link-entity name="contact" from="contactid" to="primarycontactid" visible="false" link-type="outer" alias="prmContact">' +
'< attribute name="telephone3" />' +
'< attribute name="description" />' +
'</ link-entity>' +
'</ entity>' +
'</ fetch>'].join('');
var encodedFetchXML = encodeURIComponent(accountFetchXML);
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts?fetchXml=" + encodedFetchXML, true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
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) {
var results = JSON.parse(this.response);
for (var i = 0; i < results.value.length; i++) {
var accountDetails = results.value[i];
//Single Line Text
var nameValue = accountDetails['name'];
}
}
else {
alert(this.statusText);
}
}
};
req.send();
于 2018-08-08T20:08:39.097 回答