2016-12-12 86 views
0

我有超過5000條記錄要使用此查詢獲取,但每次都獲得空值的cookie。我意識到鏈接實體是這裏的問題,因爲當我刪除它時,我每次都會得到cookie。CRM FetchXML獲取超過5000條記錄

<fetch version="1.0" mapping="logical" distinct="true" page="1" count="2000" > 
    <entity name="listmember" > 
     <link-entity name="contact" from="contactid" to="entityid" alias="c" > 
      <attribute name="contactid" /> 
      <attribute name="telephone1" /> 
      <link-entity name="phonecall" from="ic_customer" to="contactid" alias="pc" link-type="outer" distinct="true"> 
       <attribute name="activityid" /> 
       <filter type="and" > 
        <filter type="or" > 
         <condition attribute="statuscode" operator="eq" value="1" /> 
         <condition attribute="ic_end" operator="on-or-after" value="2016-11-12" /> 
        </filter> 
       </filter> 
      </link-entity> 
      <filter type="and" > 
       <condition attribute="statecode" operator="eq" value="0" /> 
       <condition attribute="telephone1" operator="not-null" /> 
       <condition attribute="donotphone" operator="eq" value="0" /> 
      </filter> 
     </link-entity> 
     <filter type="and" > 
      <condition attribute="listid" operator="in" > 
       <value> 
        {f89087ef-7017-e611-80e3-5065f38a3951} 
       </value> 
      </condition> 
      <condition entityname="pc" attribute="activityid" operator="null" /> 
     </filter> 
    </entity> 
</fetch> 

任何人都知道如何獲得這個請求的分頁cookie?

回答

0

這個問題的解決方案是你需要在根實體上指定ID列。在此示例中,您需要將listmemberid屬性添加到實體的根listmember實體。

<fetch version="1.0" mapping="logical" distinct="true" page="1" count="2000" > 
    <entity name="listmember" > 
     <attribute name="listmemberid" /> 
     <link-entity name="contact" from="contactid" to="entityid" alias="c" > 
      <attribute name="contactid" /> 
      <attribute name="telephone1" /> 
      <link-entity name="phonecall" from="ic_customer" to="contactid" alias="pc" link-type="outer" distinct="true"> 
       <attribute name="activityid" /> 
       <filter type="and" > 
        <filter type="or" > 
         <condition attribute="statuscode" operator="eq" value="1" /> 
         <condition attribute="ic_end" operator="on-or-after" value="2016-11-12" /> 
        </filter> 
       </filter> 
      </link-entity> 
      <filter type="and" > 
       <condition attribute="statecode" operator="eq" value="0" /> 
       <condition attribute="telephone1" operator="not-null" /> 
       <condition attribute="donotphone" operator="eq" value="0" /> 
      </filter> 
     </link-entity> 
     <filter type="and" > 
      <condition attribute="listid" operator="in" > 
       <value> 
        {f89087ef-7017-e611-80e3-5065f38a3951} 
       </value> 
      </condition> 
      <condition entityname="pc" attribute="activityid" operator="null" /> 
     </filter> 
    </entity> 
</fetch> 
0

讀你的帖子提醒我,我聽說過這個之前,果然我去我的筆記,看到「Fetchxml linkentity不支持分頁」。但是,我似乎無法找到關於限制的任何官方信息,這感覺很奇怪。

無論如何,我敢肯定它是取查詢與鏈接實體不支持分頁的情況。嘗試使用QueryExpression執行代替。

-1
using System; 
using System.Data; 
using Microsoft.SqlServer.Dts.Pipeline.Wrapper; 
using Microsoft.SqlServer.Dts.Runtime.Wrapper; 
using Microsoft.Xrm.Sdk; 
using System.ServiceModel.Description; 
using Microsoft.Xrm.Sdk.Client; 
using Microsoft.Xrm.Sdk.Query; 

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute] 
public class ScriptMain : UserComponent 
{ 
    IOrganizationService organizationservice; 

    public override void PreExecute() 
    { 
     base.PreExecute(); 

     ClientCredentials credentials = new ClientCredentials(); 

     credentials.UserName.UserName = "username"; 

     credentials.UserName.Password = "password"; 


     credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; 

     organizationservice = new OrganizationServiceProxy(
      new Uri("_your org service_Organization.svc"), null, credentials, null); 
    } 

    public override void PostExecute() 
    { 
     base.PostExecute(); 
    } 

    public override void CreateNewOutputRows() 
    { 
     QueryExpression query = new QueryExpression("account") 
     { 
      ColumnSet = new ColumnSet(new string[] { "accountnumber" }), 
      PageInfo = new PagingInfo() 
      { 
       Count = 250, 
       PageNumber = 1, 
       ReturnTotalRecordCount = false, 
       PagingCookie = null 
    } 
     }; 

     EntityCollection results = null; 

     while (true) 
     { 



      results = organizationservice.RetrieveMultiple(query); 

      foreach (Entity record in results.Entities) 
      { 
       accountBuffer.AddRow(); 


       if (record.Contains("accountnumber")) 
        accountBuffer.accountnumber = record.GetAttributeValue<string>("accountnumber"); 


      } 



      if (results.MoreRecords) 
      { 
       query.PageInfo.PageNumber++; 
       query.PageInfo.PagingCookie = results.PagingCookie; 
      } 
      else 
      { 
       break; 
      } 
     } 

    } 




} 
+0

試圖解釋代碼。 – Gahan