web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Paging cookie is required when trying to retrieve a set of records on any high pages.

(0) ShareShare
ReportReport
Posted on by 437

Hi All, 

I am getting error "Paging cookie is required when trying to retrieve a set of records on any high pages."

I have set 

// Set the paging cookie to the paging cookie returned from current results.
qe.PageInfo.PagingCookie = results.PagingCookie;

I am using CRM 9.0 on line vesrion. Is is that CRM 9 have any issue on this 

Below is my code.

public static void UpdateField
{
try
{

var crmService = CRMHelperClass.GetCRMService();
QueryExpression qe = new QueryExpression();
qe.EntityName = "opportunity";
qe.ColumnSet = new ColumnSet();

qe.ColumnSet = new ColumnSet(new string[] { "new_xx1", "new_xx2", "new_xx3", "statuscode" }); //"description",
//Condition where task attribute equals account id.
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "statecode";
condition.Operator = ConditionOperator.Equal;
condition.Values.Add(0);
qe.Criteria.AddCondition(condition);


// The number of records per page to retrieve.
int queryCount = 3;
// Initialize the page number.
int pageNumber = 1;
// Initialize the number of records.

// Assign the pageinfo properties to the query expression.
qe.PageInfo = new PagingInfo();
qe.PageInfo.Count = queryCount;
qe.PageInfo.PageNumber = pageNumber;

// The current paging cookie. When retrieving the first page,
// pagingCookie should be null.
qe.PageInfo.PagingCookie = null;

//Code if Opportunity have more than 5000 records
qe.PageInfo = new PagingInfo();
qe.PageInfo.Count = 5000;
qe.PageInfo.PageNumber = 1;
qe.PageInfo.ReturnTotalRecordCount = true;

while (true)
{
EntityCollection results = crmService.RetrieveMultiple(qe);
foreach (Entity r in results.Entities)
{
statusCode = ((OptionSetValue)r.Attributes["statuscode"]).Value;
if (statusCode == 1) // if Opp in INprogress
{

try
{
  // some logic
crmService.Update(_opportunities);

}
}
catch (Exception ex)
{

}
}

}
}

if (results.MoreRecords)
{
// Increment the page number to retrieve the next page.
qe.PageInfo.PageNumber++;
// Set the paging cookie to the paging cookie returned from current results.
qe.PageInfo.PagingCookie = results.PagingCookie;
}
else
{
// If no more records are in the result nodes, exit the loop.
break;
}
}

}
catch (System.ServiceModel.FaultException ex)   // I am getting error here.
{
}

catch (Exception ex)
{
}

}

KIndly suggest.

*This post is locked for comments

I have the same question (0)
  • Flydancer Profile Picture
    1,332 on at
    RE: Paging cookie is required when trying to retrieve a set of records on any high pages.

    Are these 2 different codesnippets concatenated or why are you building PagingInfo two times?

    Please format and mark it properly.

  • windyMill Profile Picture
    437 on at
    RE: Paging cookie is required when trying to retrieve a set of records on any high pages.

    Sorry by mistke i pasted pageinfo 2 times.

    But still I m getting same error.

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Paging cookie is required when trying to retrieve a set of records on any high pages.

    Hi,

    Try with this -

           public static void UpdateField()
            {
                try
                {
                    int statusCode = 0;
                    var crmService = CRMHelperClass.GetCRMService();
                    QueryExpression qe = new QueryExpression();
                    qe.EntityName = "opportunity";
                    qe.ColumnSet = new ColumnSet();
                    qe.ColumnSet = new ColumnSet(new string[] { "new_xx1", "new_xx2", "new_xx3", "statuscode" }); //"description",
                                                                                                                  //Condition where task attribute equals account id. 
                    ConditionExpression condition = new ConditionExpression();
                    condition.AttributeName = "statecode";
                    condition.Operator = ConditionOperator.Equal;
                    condition.Values.Add(0);
                    qe.Criteria.AddCondition(condition);
    
                    // The number of records per page to retrieve.
                    int queryCount = 3;
                    // Initialize the page number.
                    int pageNumber = 1;
                
    
                    // Assign the pageinfo properties to the query expression.
                    qe.PageInfo = new PagingInfo();
                    qe.PageInfo.Count = queryCount;
                    qe.PageInfo.PageNumber = pageNumber;
    
                    // The current paging cookie. When retrieving the first page, 
                    // pagingCookie should be null.
                    qe.PageInfo.PagingCookie = null;
    
                    while (true)
                    {
                        EntityCollection results = crmService.RetrieveMultiple(qe);
                        foreach (Entity r in results.Entities)
                        {
                            statusCode = ((OptionSetValue)r.Attributes["statuscode"]).Value;
                            if (statusCode == 1) // if Opp in INprogress
                            {
                                try
                                {
                                    // some logic
                                    // crmService.Update(_opportunities);
    
                                }
                                catch (Exception ex)
                                {
                                    throw ex;
                                }
    
                            }
    
                        }
                    }
                }
                catch (Exception ex)
                {
    
                }
            }


  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Paging cookie is required when trying to retrieve a set of records on any high pages.

    Hi,

    I don't think there is anything wrong the way you are using paging cookie. The error seems to be related to you update operation (or the logic which you have you have inside your for loop). For example, the statement "statusCode = ((OptionSetValue)r.Attributes["statuscode"]).Value;" will throw object reference null exception if the attributes doesn't contain status code field.  Also, you have used _opportnities in the update method, what is that?

    What is the error you are getting. Try to break down you code, instead of focusing on the pagin, focus on the update part and see if you have missed anything there.

    Hope this helps.

  • David Jennaway Profile Picture
    14,065 on at
    RE: Paging cookie is required when trying to retrieve a set of records on any high pages.

    When do you get the error - is it the first call to RetrieveMultiple, or a subsequent call ?

    I'd also test the code to see if you still get the issue if you don't have the Update call. If the update affects opportunities, that could affect the results from the query, which could affect paging

  • windyMill Profile Picture
    437 on at
    RE: Paging cookie is required when trying to retrieve a set of records on any high pages.

    Hi Goutam ,

    Thanks once again to share your views .

    I did  some change in code and it started working .

    EntityCollection results = crmService.RetrieveMultiple(qe);

    if(results != null)  // I added this condition and then put for  loop inside it

    then placed results.more condition  outside of above if condition.

    Any views..

    public static void UpdateField

    {

    try

    {

    var crmService = CRMHelperClass.GetCRMService();

    QueryExpression qe = new QueryExpression();

    qe.EntityName = "opportunity";

    qe.ColumnSet = new ColumnSet();

    qe.ColumnSet = new ColumnSet(new string[] { "new_xx1", "new_xx2", "new_xx3", "statuscode" }); //"description",

    //Condition where task attribute equals account id.

    ConditionExpression condition = new ConditionExpression();

    condition.AttributeName = "statecode";

    condition.Operator = ConditionOperator.Equal;

    condition.Values.Add(0);

    qe.Criteria.AddCondition(condition);

    // The number of records per page to retrieve.

    int queryCount = 3;

    // Initialize the page number.

    int pageNumber = 1;

    // Initialize the number of records.

    // Assign the pageinfo properties to the query expression.

    qe.PageInfo = new PagingInfo();

    qe.PageInfo.Count = queryCount;

    qe.PageInfo.PageNumber = pageNumber;

    // The current paging cookie. When retrieving the first page,

    // pagingCookie should be null.

    qe.PageInfo.PagingCookie = null;

    //Code if Opportunity have more than 5000 records

    qe.PageInfo = new PagingInfo();

    qe.PageInfo.Count = 5000;

    qe.PageInfo.PageNumber = 1;

    qe.PageInfo.ReturnTotalRecordCount = true;

    while (true)

    {

    EntityCollection results = crmService.RetrieveMultiple(qe);

    if(results != null)  // I added this condition and then put for  loop inside it

    {

     foreach (Entity r in results.Entities)

    {

    statusCode = ((OptionSetValue)r.Attributes["statuscode"]).Value;

    if (statusCode == 1) // if Opp in INprogress

    {

    try

    {

     // some logic

    crmService.Update(_opportunities);

    }

    }

    catch (Exception ex)

    {

    }

    }

    if (results.MoreRecords)    // placed outside of for loop

    {

    // Increment the page number to retrieve the next page.

    qe.PageInfo.PageNumber++;

    // Set the paging cookie to the paging cookie returned from current results.

    qe.PageInfo.PagingCookie = results.PagingCookie;

    }

    else

    {

    // If no more records are in the result nodes, exit the loop.

    break;

    }

    }

    }

    catch (System.ServiceModel.FaultException ex)   // I am getting error here.

    {

    }

    catch (Exception ex)

    {

    }

  • gdas Profile Picture
    50,091 Moderator on at
    RE: Paging cookie is required when trying to retrieve a set of records on any high pages.

    Hi,

    Glad to hear that. Please close the thread.

  • Suggested answer
    Kjeld Poulsen Profile Picture
    180 on at
    RE: Paging cookie is required when trying to retrieve a set of records on any high pages.

    I got this error on a C# Linq query, using the SDK, and that cat is suppose to handle the paging-cookie behind your back, so it was really strange.

    i was joining  activityparty  to campaignresponse  to find all contacts that had a campaign response in the campaign. It turned out that i had to do the join the other way around, so instead of starting with activityparty that has the partyid = contact. i had to start with campaignrepoinse

    so ERROR ON:  from ap in ctx.ActivityPartySet join cr in ctx.CampaignResponseSet on ap.activityid equals cr.activity.id

    while this worked:  from cr in ctx.CampaignResponseSet join ap in ctx.ActivityPartySet on ap.activityid.Id equals cr.activity

    Not sure why, but i think it is a bug. Hope this workaround can help others. This solution works for me because I am 100% sure that the partylist (customer) has only one record for each campaignresponse.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans