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
Post a Comment