Count Records in javascript

Count Records in javascript

Hello,
I'm using a widget on my page, and I need to write the number of fetched records. But the thing is, you can only fetch max 200 records, so I tried to use a loop.

The code below is an infinite loop, because the API call never happens. Is this related to the the promise inside it, or am I just not seeing something obvious? (The appName and reportName is changed here.)
  1. $(document).ready(function(){

    var count = 0;
    var done = false;

    while (done == false)
    {
    ZOHO.CREATOR.init(done, count)
    .then(function(data) {
    var configI = 
    {
    appName : 'appname',
    reportName : 'reportname',
    criteria: 'ID != 0',
    page : 1,
    pageSize : 200
    }

    ZOHO.CREATOR.API.getAllRecords(configI).then(function(response){
    var recordArrInfo = response.data;

    count += recordArrInfo.length;
    if (recordArrInfo.length < 200)
    {
    done = true;
    }
    else
    {
    configI.page += 1;
    }
    });
    });
    }
    }
How can I count the records of my report using javascript?

Thanks,
Ati