0

I have this snippet that works partially (trying until 2000 records), but the automation or the cloudpage stop and finish before processing all the data; How to work with WS PROXY with the functions below? Would WS PROXY work in this case?

<script runat="server">
  Platform.Load("Core","1.1.1");
     var dataRows = Platform.Function.LookupRows('DENAME','Email','[email protected]');
     if(dataRows && dataRows.length > 0) {
          for(var i=0; i<dataRows.length; i++) {
var id = dataRows[i].Id;
var contentType  = "application/x-www-form-urlencoded"
var req = dataRows[i].DataXML; // it's text data, base64 string
var url = 'https://api';
var result = HTTP.Post(url, contentType, req);
var aRes = Platform.Function.ParseJSON(result.Response.toString());
var val = aRes.pURL;
var TestDE = DataExtension.Init("..-C4D9-4036-B0FC-379A0B71FFB5");
var upDE = TestDE.Rows.Add({"Id":"RequestviaSSJS",PURL:val,Invoice:id});         

          }
     }
</script>

1 Answer 1

3

LookupRows function retrieval is limited by 2000 records.

Yet, there is a similar function that you can use to retrieve more records - LookupOrderedRows (or better to refer to this since official SSJS documentation is unclear):

<script runat="server">
Platform.Load("Core", "1");
    var DeName = ''; //Add your Data Extension's name
    var RowCount = Platform.Function.TreatAsContent('%'+'%=DataExtensionRowCount("' + DeName + '")=%' + '%');
    var dataRows = Platform.Function.LookupOrderedRows(DeName, RowCount, 'Email DESC', 'Email', '[email protected]');
    if(dataRows && dataRows.length > 0) {
        for(var i = 0; i < dataRows.length; i++) {
            var id = dataRows[i].Id;
            var contentType = "application/x-www-form-urlencoded"
            var req = dataRows[i].DataXML; // it's text data, base64 string
            var url = 'https://api';
            var result = HTTP.Post(url, contentType, req);
            var aRes = Platform.Function.ParseJSON(result.Response.toString());
            var val = aRes.pURL;
            var TestDE = DataExtension.Init("..-C4D9-4036-B0FC-379A0B71FFB5");
            var upDE = TestDE.Rows.Add({"Id":"RequestviaSSJS",PURL:val,Invoice:id});         
        }
    }
</script>

You can use the DataExtensionRowCount AMPscript function to dynamically set 2nd argument in the SSJS function to pull always all existing records.

Lastly, please consider that the bigger number of records you would like to retrieve - the closer you would get to hit the timeout of the Script activity (30 mins) or CloudPage, thus other approaches of achieving your goal should be reviewed.

upd: your code does not use WSProxy but Platform functions of SSJS. If you would like to retrieve DE's records by WSProxy check this article but I can tell you it will be working slower.

You must log in to answer this question.

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