I need to display data from a DataExtension (with more than 2500 records) on a landing page via the the API. As you know there is a cap of 2500 records per API call. But thanks to the StatusOutput of MoreDataAvailable I can keep looping until I get a response of "OK". AMPScript supports a FOR loop but how can I get the count?

This is what I am currently doing. FOR @i = 1 to @emailCount DO

I need to simulate something like this: while @statusOutput == "MoreDataAvailable"


SET @retrieveRequest = CreateObject("RetrieveRequest")
SetObjectProperty(@retrieveRequest, "ObjectType", "DataExtensionObject[DATAEXTENSION]")
AddObjectArrayItem(@retrieveRequest, "Properties","EMAIL_ADDRESS")

/* Execute the Retrieve */
SET @emails = InvokeRetrieve(@retrieveRequest, @statusOutput, @requestId)

IF @statusOutput == "MoreDataAvailable" THEN
  SET @isLoop = 1
  SET @isLoop = 0

Server-Side JavaScript will give you the flexibility you need. Something like this should do the trick:

<script runat="server">

var rr = Platform.Function.CreateObject("RetrieveRequest");
Platform.Function.SetObjectProperty(rr, "ObjectType", "DataExtensionObject[DENAME]");
Platform.Function.AddObjectArrayItem(rr, "Properties", "EmailAddress");

do {

  var results = [0,0];
  var rows = Platform.Function.InvokeRetrieve(rr, results);
  var status = results[0];
  var requestId = results[1];
  Write("<br>status: " + status);
  Write("<br>requestId: " + requestId);

  if (rows != null) {

     Write("<br>rows.length: " + rows.length);

     for (var i in rows) {
       Write("<br>i:" + i + " " + rows[i].Properties[0].Value);

  rr.ContinueRequest = requestId;

} while (status == "MoreDataAvailable")

  • Thanks Adam, I was not aware that I could use SSJ.
    – user5105
    Nov 23 '16 at 23:13
  • It works well on landing pages and script activities... Not as good in emails. Nov 23 '16 at 23:15
  • Hi Adam, I am trying to use your script but I am getting the following error, startIndex cannot be larger than length of string. Parameter name: startIndex . Any ideas what what this error means? Jun 19 '17 at 14:04
  • There are no string functions like that in my example. Perhaps it's somewhere else in your code? Jun 19 '17 at 14:46
  • It looks like it doesn't like do - while loop, I didn't change your code apart of DE name and Attribute name. Jun 19 '17 at 15:09

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.