2

I'd like to make multiple HTTP.Get requests in a Script Activity, based on the number of rows returned from a LookupRows function.

The issue is that it only makes the HTTP.Get request once, for the first record in the rowset. Here's my code:

<script runat="server">
Platform.Load("core","1");
var dataRows = Platform.Function.LookupRows('Reconciliation Report','Missing',1);
     if(dataRows && dataRows.length > 0) {
          for(var i=0; i<dataRows.length; i++) {
            var createInteractions = HTTP.Get('http://pages.company.com/ProcessMissing');
        }
     }
</script>
1

It appears that looping HTTP.Get requests in SSJS is either broken or not supported. However, I can simply make a POST request instead and this works:

<script runat="server">
Platform.Load("core","1");
var dataRows = Platform.Function.LookupRows('Reconciliation Report','Missing',1);
     if(dataRows && dataRows.length > 0) {
          for(var i=0; i<dataRows.length; i++) {
            var createInteractions = HTTP.Post('http://pages.company.com/ProcessMissing');
        }
     }
</script>
| improve this answer | |
0

Looks like this isn't a limitation now: Tested the loop with full object logging for success and errors to a DE to upto 500 iterations in a script activity and it works.

 Platform.Load("Core","1.1.1");
//Log response object to DE 
var logRows = DataExtension.Init("DEtoLog"); 

//Lookup the get parameters from this DE
var dataRows = DataExtension.Init("GETParametersDE").Rows.Lookup(["hook"], [1]); 

if(dataRows && dataRows.length > 0) {
    for (var i = 0; i < dataRows.length; i++){
        try{
            var url = "[endpoint]?id="+dataRows[i].SubscriberKey;    

            var result = HTTP.Get(url);
            var jsonObject = Platform.Function.ParseJSON(result.Content);
            var logRow ={
                     "Status" : "Success",
                     "SubscriberKey" : jsonObject.identity.email,
                     "ID": jsonObject.identity.id,
                     "JSONresponse": result.Content
                    }

                logRows.Rows.Add(logRow);
        }         

        catch(e){

            var logRow ={
                 "Status" : "ERROR",
                 "ErrorMsg" : Stringify(e) 
                }

                logRows.Rows.Add(logRow);      
        }
    }
}

Note in a cloudpage, the same code resulted in the error

System.Threading.ThreadAbortException: Thread was being aborted. - from mscorlib

after about 150 requests. Looks like a built-in limitation to ASP.Net HTTPHandler according to https://support.microsoft.com/en-hk/help/817266/prb-system-threading-threadabortexception-error-message-when-you-use-s

| improve this answer | |

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.