使用新的 retrieveMultipleRecords 从 fetchXml 获取结果(客户端 API 参考)

Get results from fetchXml using new retrieveMultipleRecords (Client API reference)

无法确定如何使用新的 retrieveMultipleRecords(客户端 API 参考)从以下 fetchXml 中获取结果:

var request = "<fetch output-format='xml-platform' distinct='true' version='1.0' mapping='logical'>" +
"<entity name='msdyn_incidenttype'>" +
"<attribute name='msdyn_name'/>" +
"<attribute name='createdon'/>" +
"<attribute name='msdyn_estimatedduration'/>" +
"<attribute name='msdyn_incidenttypeid'/>" +
"<order attribute='msdyn_name' descending='false'/>" +
"<link-entity name='product' link-type='inner' alias='ag' from='productid' to='aka_productfamilyid'>" +
"<link-entity name='msdyn_customerasset' link-type='inner' alias='ah' from='msdyn_product' to='productid'>" +
"<filter type='and'>" +
"<condition attribute='msdyn_customerassetid' operator='eq' uiname='' uitype='msdyn_customerasset' value='${custAssetId}'/>" +
"</filter>" +
"</link-entity>" +
"</link-entity>" +
"</entity>" +
"</fetch>";

我在新客户端使用上面的fetchXml api参考如下:

var results = Xrm.WebApi.retrieveMultipleRecords("msdyn_incidenttype",request).then(
  function success(result) {
      for (var i = 0; i < result.entities.length; i++) {
          console.log(result.entities[i]);
      }
      console.log("Next page link: " + result.nextLink);
      // perform additional operations on retrieved records
  },
  function (error) {
      console.log(error.message);
      // handle error conditions
  }

我阅读的文档 (https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/xrm-webapi/retrievemultiplerecords) 指出第二个参数是选项,如果是 fetchXml(如我所用),则在此处指定它。但是我在控制台中收到以下错误:

HTTP400: BAD REQUEST - The request could not be processed by the server due to invalid syntax. (XHR)GET - https://dev.crm.dynamics.com/api/data/v9.0/msdyn_incidenttypes?fetch output-format='xml-platform' distinct='true' version='1.0' mapping='logical'>entity name='msdyn_incidenttype'>attribute name='msdyn_name'/>attribute name='createdon'/>attribute name='msdyn_estimatedduration'/>attribute name='msdyn_incidenttypeid'/>order attribute='msdyn_name' descending='false'/>link-entity name='product' link-type='inner' alias='ag' from='productid' to='aka_productfamilyid'>link-entity name='msdyn_customerasset' link-type='inner' alias='ah' from='msdyn_product' to='productid'>filter type='and'>condition attribute='msdyn_customerassetid' operator='eq' uiname='' uitype='msdyn_customerasset' value='${custAssetId}'/>/filter>/link-entity>/link-entity>/entity>/fetch>

我是不是遗漏了什么?

你应该像下面这样在前面加上"?fetchXml=":

Xrm.WebApi.retrieveMultipleRecords("msdyn_incidenttype", "?fetchXml= " + request).then(
                function success(result) {
                    return result;
                },
                function (error) {
                    console.log("failed with error: ", error);
                    return null;
                }
            );

options
OData system query options or FetchXML query to retrieve your data.

  • Following system query options are supported: $select, $top, $filter, $expand, and $orderby.

  • To specify a FetchXML query, use the fetchXml attribute to specify the query.

Reference