在使用savedQuery时是否可以应用过滤器? 例如,如果保存的/预定义的视图返回多个帐户,例如以下URL“ ... / api / data / v9.0 / accounts?savedQuery = 9e3ddee9-9e74-e811-a95d-000d3a34afa9”,一种为单个帐户返回相同保存视图的结果的方法?
答案 0 :(得分:1)
您可以将获取XML发送到Web API。只需通过“高级查找”下载视图的获取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();