Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
How to repeat a function without effecting repeating the token

How do I modify the repeat loop function without it repeating the token variable in the function rowcount()?

function rowcount()
{ 
  var token = getAccessToken();
  var module = "sHistory";
  var rows = 0;
  var go = true;
  var i = 1;
  var data;
  
   
   while (go) {
    data = getRecordsByPage(i,200,token,module);
    
    if (Number(data.info.count) < 200) {
      go = false;
    };
    if ((i%10) == 0) {
       go = false; 
    }
    rows = Number(rows) + Number(data.info.count);
      i++;
   
      Logger.log(rows)
      }
      return rows
   }
  
  
function repeatloop()
{
  let counter = 0;

  for(var i = 1; i <= 93; i++)
      {
        {
        Utilities.sleep(10000);
        Logger.log(i);

        counter += rowcount();
        Logger.log(counter);
        }
      }
      return rowcount().rows;   
  } 

What I am also trying to do is let the count continue because right now it goes in an increment of 2000, but I need it to continue like 200...400..600..800...1000...1200...1400...1600...1800...2000...2200. and it goes on until the loop stops.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can make the token a global variable like this:

var token;
function rowcount()
{
  var module = "sHistory";
  var rows = 0;
  var go = true;
  var i = 1;
  var data;
  
   
   while (go) {
    data = getRecordsByPage(i,200,token,module);
    
    if (Number(data.info.count) < 200) {
      go = false;
    };
    if ((i%10) == 0) {
       go = false; 
    }
    rows = Number(rows) + Number(data.info.count);
      i++;
   
      Logger.log(rows)
      }
      return rows
   }
  
  
function repeatloop()
{
  let counter = 0;
  token = getAccessToken();

  for(var i = 1; i <= 93; i++)
      {
        {
        Utilities.sleep(10000);
        Logger.log(i);

        counter += rowcount();
        Logger.log(counter);
        }
      }
      return rowcount().rows;   
  }

Or did I understand you wrong?

about 4 years ago · Juan Pablo Isaza Report

0

I would pass the token as an optional parameter, insted to use GLOBAL variable:

function rowcount(_token = null)
{ 
  let token;
  if (_token) {token = _token;}
  else {token = getAccessToken();} 

  var module = "sHistory";
  var rows = 0;
  var go = true;
  var i = 1;
  var data;
  
   
   while (go) {
    data = getRecordsByPage(i,200,token,module);
    
    if (Number(data.info.count) < 200) {
      go = false;
    };
    if ((i%10) == 0) {
       go = false; 
    }
    rows = Number(rows) + Number(data.info.count);
      i++;
   
      Logger.log(rows)
      }
      return rows
   }
  
  
function repeatloop()
{
  let token = getAccessToken();
  let counter = 0;

  for(var i = 1; i <= 93; i++)
      {
        {
        Utilities.sleep(10000);
        Logger.log(i);

        counter += rowcount(token);
        Logger.log(counter);
        }
      }
      return rowcount(token).rows;   
  } 
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!