How to get more records using FetchXml with paging cookies using Power Shell Script

Connect D365 using below details:

 $Username="APY***@Trailcrm.com"

$Password="apy****"

$pwd = ConvertTo-SecureString $Password -AsPlainText -Force 

$credentials = New-Object System.Management.Automation.PSCredential($Username, $pwd)

$CRMConnection = Connect-CrmOnline -Credential $credentials -ServerUrl "https://apytrailcrm****.crm.dynamics.com/" -ForceOAuth

Declare variables:

$pagingCookie=""

$page=1

$count=5000

Using do while loop with FetchXml with below code will get more records

do{

    $varFetch = Get-CrmRecordsByFetch -conn $CRMConnection -Fetch @"

   <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">

    <entity name="contact">

    <attribute name="fullname" />

    <attribute name="contactid" />

    <order descending="false" attribute="fullname" />

    <filter type="and">

      <condition attribute="statecode" operator="eq" value="0" />

    </filter>

    </entity>

    </fetch>

"@ -TopCount $count -PageNumber $page -PageCookie $pagingCookie

$pagingCookie=$varFetch.PagingCookie

$page++

}while($varFetch.NextPage -ne $false)

Comments

Popular posts from this blog

Basic Plugin Code in D365 using C#

CURD (Create, Update, Retrieve and Delete) Operation in D365 using Power Shell Script

Meta Data Using WebApiRequest