1

Is it possible to retrieve all rows for a DataExtension with a RetrieveRequest?

I'm blocking by 2500 max-retrieve function restriction.

My cloudpage blocked, when I repeat two or three times this code:

data = DE_2.Rows.Retrieve();
recordCount = data.length;

for( i = 0; i < recordCount; i++) {
    var rNOMBRE = data[i].NOMBRE;
    Write(i + ": " + rNOMBRE + " <br/>");
}

I got more than 10k rows... how could I "retrieve" all that for make execute some automatisms?

2

1 Answer 1

4

If you need to use SSJS, I would use the SSJS Web Services capability to do a Retrieve Request API call. From there you can do a ContinueRequest until all data has been collected. See below:

<script runat="server">

  Platform.Load("Core","1.1.1");

var rr = Platform.Function.CreateObject("RetrieveRequest");
Platform.Function.SetObjectProperty(rr, "ObjectType", "DataExtensionObject[YourDEKey]");

Platform.Function.AddObjectArrayItem(rr, "Properties", "NOMBRE");
Platform.Function.AddObjectArrayItem(rr, "Properties", "YourAttribute1");
Platform.Function.AddObjectArrayItem(rr, "Properties", "YourAttribute2");



do { 
    var results = [0,0];
    var rows = Platform.Function.InvokeRetrieve(rr, results);

    var runstatus = results[0];
    var requestId = results[1];

     if (rows != null) {

        //var valueStr = '[';

        for (var i in rows) {

          var rNOMBRE = rows[i].NOMBRE;
          Write(i + ": " + rNOMBRE + " <br/>");

        } 
    } 

    rr.ContinueRequest = requestId;


} while (runstatus == "MoreDataAvailable")

</script>

If you are not restricted to SSJS, you can pull this via AMPScript. It is a bit more limited in that it requires a filter, which means you need to have a field with the same value for each record. E.g. I tend to place a field named 'Secret' with a value of '1' in all my DEs, to help me pull via AMPscript.

%%[

SET @Rows = LookupOrderedRows(@YourDE, DataExtensionRowCount(@YourDE),"SortableAttribute asc", "FlagField", "Value") 

]%%
4
  • Tried to edit it as the code itself doesn't work. David Reed rejected my edit so I'll write it here to save time for those visitors like me using this code. Above code fails in the part that sets the "sfp" property. Its OPTIONAL, but it should be like: var sfp = Platform.Function.CreateObject("SimpleFilterPart"); Platform.Function.SetObjectProperty(sfp, "Property", "YourAttribute1"); Platform.Function.SetObjectProperty(sfp, "SimpleOperator", "equals"); Platform.Function.AddObjectArrayItem(sfp, "Value", "AnyValue"); Platform.Function.SetObjectProperty(rr, "Filter", sfp); Jul 24, 2018 at 9:45
  • What error are you getting? I have run this almost identical code with no issues. Jul 24, 2018 at 13:33
  • Well in your code you set "sfp" property without defining it (Line 13). If you copy your code and paste it without setting "sfp", it won't work as "sfp" does not exists. Aug 7, 2018 at 11:17
  • It does appear that the filter part was included in my example code - likely a poor copy/paste job on my part. To better fit the OPs question, where a filter is not needed, I have removed it from the answer. Aug 7, 2018 at 13:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .