简体   繁体   English

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

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

I use Web Resource JavaScript file to retrieve multiple records from CRM.我使用 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);

After I get paging-cookie in first request I try to send it to the second request to retrieve data for second page:在第一个请求中获得 paging-cookie 后,我尝试将其发送到第二个请求以检索第二个页面的数据:

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

Original cookie from response looks like:来自响应的原始 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

I tried to transform and send cookie according to documentation: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/org-service/page-large-result-sets-with-fetchxml我尝试根据文档转换和发送 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) In first case when I use GetDecodedCookie1 I get: 1)在第一种情况下,当我使用 GetDecodedCookie1 时,我得到:

Script error. in  at 0:0  null

在此处输入图片说明

My Query String Parameters are broken.我的查询字符串参数坏了。

2) In second case when I use GetDecodedCookie1 Query String Parameters looks fine but I get: 2)在第二种情况下,当我使用 GetDecodedCookie1 查询字符串参数时看起来不错,但我得到:

Malformed XML in the Paging Cookie

What is the issue here ?这里有什么问题?

the Paging Cookie needs the id of the last record, include the "accountid" as an attribute to your fetchxml Paging Cookie 需要最后一条记录的 id,将“accountid”作为属性包含在您的 fetchxml 中

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

Is the use of FetchXML mandatory to query the Web API?是否必须使用 FetchXML 来查询 Web API? Otherwise, you can simplify your life by using OData.否则,您可以使用 OData 简化您的生活。 Your FetchXML translated to an OData query is:您的 FetchXML 转换为 OData 查询是:

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

Which would return a response similar to the one below IF there would be more than 5000 accounts in Dynamics, otherwise it would not contain a @odata.nextLink attribute (I've collapsed value collection for better readability):如果 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"
}

After retrieving this response you just have to parse it and do a request to the link given by @odata.nextLink attribute to retrieve the next batch of records, in my case this link would retrieve account 5001 to 10000.检索此响应后,您只需解析它并对@odata.nextLink 属性给出的链接发出请求以检索下一批记录,在我的情况下,此链接将检索帐户 5001 到 10000。

For more information on how to Query Data using the Web API click here for the official documentation.有关如何使用 Web API 查询数据的更多信息,请单击此处获取官方文档。

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

相关问题 Dynamics CRM Web API 8.2无法在JavaScript调用中检索页面cookie - Dynamics CRM web api 8.2 does not retrieve page cookie in JavaScript call 将CRM动态在线升级后的/api/data/v8.2到/api/data/v9.0? - /api/data/v8.2 to /api/data/v9.0 after dynamics CRM online upgrade? Dynamics CRM 365 WebApi 8.2 AddListMembersList 方法 - Dynamics CRM 365 WebApi 8.2 AddListMembersList method 动态CRM 2016-Web API查询-动态值 - dynamics crm 2016 - Web API query- dynamic values 我们如何在js中识别Dynamics CRM Web api版本? - How can we identify the Dynamics CRM web api version in js? 来自外部站点的Dynamics CRM Web API(JavaScript) - Dynamics CRM Web API from external site (javascript) 将Dynamics CRM Web API直接消费到Django Web应用程序中的PostgreSQL数据库中 - Consume Dynamics CRM Web API directly into PostgreSQL database in Django web app Dynamics CRM web api FetchXml 返回带有“2_x002e_”的链接实体命名,两者之间类似 - Dynamics CRM web api FetchXml returns linked Entities naming with '2_x002e_' and similar in between Microsoft Dynamics CRM 中来自 Web API 的查找字段格式化值未定义(无法获取格式化值) - Lookup field formatted value from Web API in Microsoft Dynamics CRM is undefined (cannot get formatted value) 使用新的Web API和JavaScript POST在Dynamics CRM 2016中创建QuoteProduct - Create QuoteProduct in Dynamics CRM 2016 using new Web API and JavaScript POST
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM