1

I followed part of the solution posted by @Gortonington here: How to improve this SSJS, but the following code does not reach the end of the DataExtension and unless I break, moreData always reads true and the script goes into an infinite loop until it aborts.

(BTW, I tried to do a query via ssjs to get the DE's record count and that failed when I added Count() to the SELECT. This is is my alternative approach)

My script

<script type="text/javascript" runat='server'>
    Platform.Load("Core", "1.1");

function Write(str) {
    Platform.Response.Write(str);
}
function Stringify(obj) {
    return Platform.Function.Stringify(obj);
}
try{
    var proxy = new Script.Util.WSProxy();
    var cols = ["account_id","audience_file"];
    var r = 0;
    var moreData = true;
    var reqID = null;
    var data;
    var recCount = 0;

do {
    moreData = false; //in case we don't make it in to the data conditional
    if (reqID) {props['ContinueRequest'] = reqID;} //set ContinueRequest ID if we have requestID from a previous run
    data = proxy.retrieve("DataExtensionObject[Audience_Transitory]", cols);

    if(data != null) {
        moreData = data.HasMoreRows;
        reqID = data.RequestID;
        if(data && data.Results) {
           Write("Has More: " + moreData);
           recCount = Number(data['Results'].length) + Number(recCount);
           Write("</br>recCount " + recCount);
        }
    }//if
    r++;

    if(r==40){break;}  //This is because moreData is always true.

} while(moreData);

Write("ttlCount: " + recCount + "</br>");

} catch (err) {
    //Platform.Function.InsertData("DEBUGGING",["DebugMessage","Timestamp","ImportType"],[err,d,"DebugScript"]);
}

</script>
  • Does this need to be in SSJS or via the API? – Gortonington Apr 25 at 19:03
2

The simpler solution to get the rowcount of a Data Extension is to utilize the DataExtensionRowcount() AMPscript function.

Simply put in %%[ Set @DECount = DataExtensionRowCount('myDE') ]%% and the return of @DECount will be the rowcount of your DE.

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.