【问题标题】:Dynamics CRM web api 8.2 'Malformed XML in the Paging Cookie'Dynamics CRM web api 8.2“分页 Cookie 中的 XML 格式错误”
【发布时间】:2019-02-12 15:38:06
【问题描述】:

我使用 Web Resource JavaScript 文件从 CRM 中检索多条记录。

var fetchXML = `
            <fetch mapping="logical" output-format="xml-platform" version="1.0" page="1">
              <entity name="account" >
                <attribute name="name" />
              </entity>
            </fetch>`;

var query = "accounts?fetchXml=" + fetchXML;

callWebAPI(query);

在第一个请求中获得 paging-cookie 后,我尝试将其发送到第二个请求以检索第二页的数据:

<fetch mapping="logical" output-format="xml-platform" version="1.0" page="2" paging-cookie="cookie i get from first request"
     ...
</fetch>`;

来自响应的原始 cookie 如下所示:

%253ccookie%2520page%253d%25221%2522%253e%253cname%2520last%253d%2522Deco%2520Voyages%2522%2520firstnull%253d%25221%2522%2520%252f%253e%253caccountid%2520last%253d%2522%257b9AFBEAA6-9EA7-E711-8103-70106FAA4841%257d%2522%2520first%253d%2522%257b0A86656D-BEA7-E711-8103-70106FAA4841%257d%2522%2520%252f%253e%253c%252fcookie%253e

我尝试根据文档转换和发送 cookie:https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/org-service/page-large-result-sets-with-fetchxml

var transformedCookie1 = GetDecodedCookie1(decodeURIComponent(decodeURIComponent(pagingcookie)));

var transformedCookie2 = GetDecodedCookie2(decodeURIComponent(decodeURIComponent(pagingcookie)));

function GetDecodedCookie1(cookie) {
    return cookie.replace(/</g, "&lt;")
                 .replace(/>/g, "&gt;")
                 .replace(/"/g, "&quot;")
}

function GetDecodedCookie2(cookie) {
    return cookie.replace(/</g, "%26lt;")
                 .replace(/>/g, "%26gt;")
                 .replace(/"/g, "%26quot;")
}

1) 在第一种情况下,当我使用 GetDecodedCookie1 时,我得到:

Script error. in  at 0:0  null

我的查询字符串参数已损坏。

2) 在第二种情况下,当我使用 GetDecodedCookie1 查询字符串参数看起来不错但我得到:

Malformed XML in the Paging Cookie

这里有什么问题?

【问题讨论】:

  • 你解决了吗?
  • 很遗憾,即使我在 fetchXML 中添加帐户 ID,错误仍然存​​在。

标签: javascript xml dynamics-crm


【解决方案1】:

Paging Cookie 需要最后一条记录的 id,将“accountid”作为属性包含在您的 fetchxml 中

希望对您有所帮助 - M.Acosta.D

【讨论】:

    【解决方案2】:

    查询 Web API 是否必须使用 FetchXML?否则,您可以使用 OData 简化您的生活。您转换为 OData 查询的 FetchXML 是:

    https://[Organization URI]/api/data/v8.2/accounts?$select=name
    

    如果 Dynamics 中有超过 5000 个帐户,它将返回类似于以下响应的响应,否则它将不包含 @odata.nextLink 属性(我已折叠值集合以提高可读性):

    {
         "@odata.context": "https://[Organization URI]/api/data/v8.2/$metadata#accounts(name)",
         "value": [],
         "@odata.nextLink": "https://[Organization URI]/api/data/v8.2/accounts?$select=name&$skiptoken=%3Ccookie%20pagenumber=%222%22%20pagingcookie=%22%253ccookie%2520page%253d%25221%2522%253e%253caccountid%2520last%253d%2522%257b92655027-054C-E911-A817-000D3ABA3F3F%257d%2522%2520first%253d%2522%257b93C71621-BD9F-E711-8122-000D3A2BA2EA%257d%2522%2520%252f%253e%253c%252fcookie%253e%22%20istracking=%22False%22%20/%3E"
    }
    

    检索此响应后,您只需对其进行解析并向@odata.nextLink 属性给出的链接发出请求以检索下一批记录,在我的情况下,此链接将检索帐户 5001 到 10000。

    有关如何使用 Web API 查询数据的更多信息,请单击here 获取官方文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-19
      • 1970-01-01
      • 1970-01-01
      • 2017-01-28
      • 1970-01-01
      • 2021-05-29
      • 2017-03-15
      • 2017-06-06
      相关资源
      最近更新 更多