繁体   English   中英

Dynamics CRM web api 8.2“分页 Cookie 中的格式错误的 XML”

[英]Dynamics CRM web api 8.2 'Malformed XML in the Paging Cookie'

我使用 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

这里有什么问题?

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

希望它有所帮助 - M.Acosta.D

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

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 查询数据的更多信息,请单击此处获取官方文档。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM