0

I need to count all matching records for a RetrieveRequest on the ListSubscribers object via AMPscript on a landing page. I got it to count the first 2500 rows by using this code. How do I get it to count the rest of the rows?

I found a method using the soap api and php on this page, but how do I achieve this with pure AMPscript?

SET @rr = CreateObject("RetrieveRequest")  
    SetObjectProperty(@rr, "ObjectType", "ListSubscriber")  
    AddObjectArrayItem(@rr,"Properties","SubscriberKey")  
    AddObjectArrayItem(@rr,"Properties","Status")    

Set @sf1 = CreateObject("SimpleFilterPart")
    SetObjectProperty(@sf1,"Property","ListID")
    SetObjectProperty(@sf1,"SimpleOperator","equals")
    AddObjectArrayItem(@sf1,"Value","2830313")

Set @sf2 = CreateObject("SimpleFilterPart")
    SetObjectProperty(@sf2,"Property","Status")
    SetObjectProperty(@sf2,"SimpleOperator","equals")
    AddObjectArrayItem(@sf2,"Value","Active")

Set @cf1 = CreateObject("ComplexFilterPart")
    SetObjectProperty(@cf1,"LeftOperand",@sf1)
    SetObjectProperty(@cf1,"RightOperand",@sf2)
    SetObjectProperty(@cf1,"LogicalOperator","AND")

SetObjectProperty(@rr, "Filter", @cf1)  

SET @subs = InvokeRetrieve(@rr, @statusOutput, @requestId)  

SET @activecount = RowCount(@subs)
1

You'll need to capture the ContinueRequest property and use it again to retrieve the remaining rows.

There's an example on this page:

Retrieving More than 2500 Records Using the ContinueRequest Property

It's in C#, but it'll get you going down the right path with the AMPScript you have so far:

do
{
    status = client.Retrieve(rr, out requestID, out Results);

    Console.WriteLine("Total Records: " + Results.Length);

    //Display Results
    for (int i = 0; i < Results.Length; i++)
    {
        sEvent = (SentEvent)Results[i];

        Console.WriteLine("SubKey on Event: " + sEvent.SubscriberKey);
    }

    //This call the API again to get the next 2500 records
    rr = new RetrieveRequest();
    rr.ContinueRequest = requestID;
} while (status.Equals("MoreDataAvailable"));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.