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) {
function Stringify(obj) {
    return Platform.Function.Stringify(obj);
    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==40){break;}  //This is because moreData is always true.

} while(moreData);

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

} catch (err) {

  • Does this need to be in SSJS or via the API? Commented Apr 25, 2019 at 19:03
  • Why did you overwrite the Write and Stringify functions? There's no need for this since you already imported the Platform.Load("Core", "1.1"); Commented Jan 24, 2020 at 10:12

1 Answer 1


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.

You must log in to answer this question.

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