簡體   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