php-crm-toolkit icon indicating copy to clipboard operation
php-crm-toolkit copied to clipboard

Need sample code for pagination

Open Tameem-Ahmad-com opened this issue 2 years ago • 1 comments

i need pagination example if you have , need to fetch 100 records per page

 $page = 1;
            $query = $this->xmlQuery();
            $fetchXML = $this->xmlQuery();
            $result = $client->RetrieveMultiple($query, false, null, 100, $page, true);
            foreach ($result->Entities as $contact) {
                $cont=Contacts::updateOrCreate(['crm_id'=>$contact->contactid],[
                    'crm_id'=>$contact->contactid,
                    'crm_contact_array'=>$contact,
                    'is_from_crm'=>1,
                    'is_posted'=>0,
                    
                ]);
        
                // dispatch(new CreateUpdateHubspotContactJob());
            }
            while ($result->MoreRecords) {
                $data = sprintf($fetchXML, htmlentities($result->PagingCookie, ENT_COMPAT | ENT_XML1), ++$page);
                $result = $client->RetrieveMultiple($data);
                foreach ($result->Entities as $contact) {
                    $cont=Contacts::updateOrCreate(['crm_id'=>$contact->contactid],[
                        'crm_id'=>$contact->contactid,
                        'crm_contact_array'=>$contact,
                        'is_from_crm'=>1,
                        'is_posted'=>0,
                        
                    ]);
            
                    // dispatch(new CreateUpdateHubspotContactJob());
                }
            }

Tameem-Ahmad-com avatar Oct 14 '21 16:10 Tameem-Ahmad-com

@Tameem-Ahmad-com you're almost there. Just increment $page while you have $result->MoreRecords. paging cookie is a performance measure, read more about it at https://docs.microsoft.com/powerapps/developer/data-platform/org-service/page-large-result-sets-with-fetchxml HTH

georged avatar Oct 15 '21 01:10 georged