I have a gscript that is throwing: Limit Exceeded: Drive.

I have a list of 50 rows when i click in a button some code will iterate over that list and call a gscript for each line. This gscript:

  • generate a file from a template(make a copy)
  • insert a table on the file
  • make a PDF from the file
  • move the file to a destination folder
  • send PDF via email

I already tried putting Utilities.sleep on the beginning of the gscript and not worked.

function generateDriverPaymentExtract(env, templateId, parentFolder, paymentNif, name, email, cycle) {
  console.log("GSCRIPT generateDriverPaymentExtract");
  //Utilities.sleep(100000);


  //get the document
  var newDoc = DriveApp.getFileById(String(templateId)).makeCopy("Driver" + paymentNif + " " + name + " " + cycle); //copy of a file to make multiple calls
  var realDoc = DocumentApp.openById(newDoc.getId());
  //get the body section of document
  var body = realDoc.getBody();
  var next = body.findText("InsertTableLedger");
  if (!next){
    return;
  }
  var element = body.findText("InsertTableLedger").getElement();
  var index = body.getChildIndex(element.getParent()) +1;
  insertTableLedger(body, index, paymentNif, cycle, env);
  body.replaceText("InsertTableLedger", "");
  //Save and close the document
  realDoc.saveAndClose()
  //save file as PDF
  var fileId = realDoc.getId();
  var pdf = exportPDF(fileId, parentFolder, paymentNif);
  //send file by email
  sendByEmail(pdf, email, paymentNif);
}

ER: gscript runs for all lines in table

AR: gscript is throwing error after some complete iterations

can someone point me a solution to avoid this error?

Edited (execution transcript):

[19-07-23 04:44:21:228 PDT] Starting execution
[19-07-23 04:44:21:240 PDT] console.log([GSCRIPT generateDriverPaymentExtract, []]) [0.002 seconds]
[19-07-23 04:44:21:242 PDT] console.log([paymentNif: , []]) [0 seconds]
[19-07-23 04:44:21:242 PDT] console.log([name: , []]) [0 seconds]
[19-07-23 04:44:21:243 PDT] console.log([email: , []]) [0 seconds]
[19-07-23 04:44:21:243 PDT] console.log([cycle: , []]) [0 seconds]
[19-07-23 04:44:21:457 PDT] DriveApp.getFileById([]) [0.213 seconds]
[19-07-23 04:44:24:642 PDT] File.makeCopy([Driver]) [3.184 seconds]
[19-07-23 04:44:24:643 PDT] console.log([GSCRIPT after var newDoc, []]) [0 seconds]
[19-07-23 04:44:24:643 PDT] File.getId() [0 seconds]
[19-07-23 04:44:24:697 PDT] DocumentApp.openById([]) [0.052 seconds]
[19-07-23 04:44:24:698 PDT] console.log([GSCRIPT after var realDoc, []]) [0 seconds]
[19-07-23 04:44:24:699 PDT] Document.getBody() [0 seconds]
[19-07-23 04:44:24:699 PDT] console.log([GSCRIPT after var body, []]) [0 seconds]
[19-07-23 04:44:24:701 PDT] Body.findText([InsertTableLedger]) [0.001 seconds]
[19-07-23 04:44:24:701 PDT] console.log([GSCRIPT after var next, []]) [0 seconds]
[19-07-23 04:44:24:702 PDT] Body.findText([InsertTableLedger]) [0 seconds]
[19-07-23 04:44:24:703 PDT] RangeElement.getElement() [0 seconds]
[19-07-23 04:44:24:703 PDT] console.log([GSCRIPT after var element, []]) [0 seconds]
[19-07-23 04:44:24:704 PDT] Text.getParent() [0 seconds]
[19-07-23 04:44:24:705 PDT] Body.getChildIndex([Paragraph]) [0 seconds]
[19-07-23 04:44:24:705 PDT] console.log([GSCRIPT after var index, []]) [0 seconds]
[19-07-23 04:44:25:627 PDT] Jdbc.getCloudSqlConnection([]) [0.92 seconds]
[19-07-23 04:44:25:628 PDT] JdbcConnection.createStatement() [0 seconds]
[19-07-23 04:44:25:628 PDT] JdbcStatement.setMaxRows([10000]) [0 seconds]
[19-07-23 04:44:25:629 PDT] JdbcStatement.setQueryTimeout([30]) [0 seconds]
[19-07-23 04:44:29:223 PDT] JdbcStatement.executeQuery([]) [3.593 seconds]
[19-07-23 04:44:29:224 PDT] JdbcResultSet.getMetaData() [0.001 seconds]
[19-07-23 04:44:29:225 PDT] JdbcResultSetMetaData.getColumnCount() [0 seconds]
[19-07-23 04:44:29:226 PDT] Body.insertTable([3]) [0.001 seconds]
[19-07-23 04:44:29:227 PDT] Table.appendTableRow() [0 seconds]
[19-07-23 04:44:29:228 PDT] TableRow.appendTableCell([Descritivo]) [0 seconds]
[19-07-23 04:44:29:229 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#FFFFFF, BOLD=true, BACKGROUND_COLOR=#336600}]) [0 seconds]
[19-07-23 04:44:29:230 PDT] TableRow.appendTableCell([Credit]) [0 seconds]
[19-07-23 04:44:29:231 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#FFFFFF, BOLD=true, BACKGROUND_COLOR=#336600}]) [0 seconds]
[19-07-23 04:44:29:232 PDT] TableRow.appendTableCell([Debit]) [0 seconds]
[19-07-23 04:44:29:233 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#FFFFFF, BOLD=true, BACKGROUND_COLOR=#336600}]) [0 seconds]
[19-07-23 04:44:29:234 PDT] JdbcResultSet.next() [0 seconds]
[19-07-23 04:44:29:235 PDT] Table.appendTableRow() [0 seconds]
[19-07-23 04:44:29:236 PDT] Logger.log([Col: 0, []]) [0 seconds]
[19-07-23 04:44:29:237 PDT] Logger.log([Col: 1, []]) [0 seconds]
[19-07-23 04:44:29:237 PDT] Logger.log([Col: 2, []]) [0 seconds]
[19-07-23 04:44:29:238 PDT] Logger.log([col == 2: 2, []]) [0 seconds]
[19-07-23 04:44:29:239 PDT] JdbcResultSet.getString([3]) [0 seconds]
[19-07-23 04:44:29:240 PDT] TableRow.appendTableCell([Comissão de Vendas Bolt]) [0 seconds]
[19-07-23 04:44:29:240 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:241 PDT] Logger.log([Col: 3, []]) [0 seconds]
[19-07-23 04:44:29:242 PDT] Logger.log([col == 3: 3, []]) [0 seconds]
[19-07-23 04:44:29:242 PDT] JdbcResultSet.getString([4]) [0 seconds]
[19-07-23 04:44:29:243 PDT] TableRow.appendTableCell([96.35]) [0 seconds]
[19-07-23 04:44:29:244 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:245 PDT] Logger.log([Col: 4, []]) [0 seconds]
[19-07-23 04:44:29:246 PDT] Logger.log([col == 4: 4, []]) [0 seconds]
[19-07-23 04:44:29:246 PDT] JdbcResultSet.getString([5]) [0 seconds]
[19-07-23 04:44:29:247 PDT] TableRow.appendTableCell([0]) [0.001 seconds]
[19-07-23 04:44:29:248 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:249 PDT] Logger.log([Col: 5, []]) [0 seconds]
[19-07-23 04:44:29:249 PDT] Logger.log([Col: 6, []]) [0 seconds]
[19-07-23 04:44:29:250 PDT] JdbcResultSet.next() [0 seconds]
[19-07-23 04:44:29:251 PDT] Table.appendTableRow() [0 seconds]
[19-07-23 04:44:29:251 PDT] Logger.log([Col: 0, []]) [0 seconds]
[19-07-23 04:44:29:252 PDT] Logger.log([Col: 1, []]) [0 seconds]
[19-07-23 04:44:29:253 PDT] Logger.log([Col: 2, []]) [0 seconds]
[19-07-23 04:44:29:253 PDT] Logger.log([col == 2: 2, []]) [0 seconds]
[19-07-23 04:44:29:254 PDT] JdbcResultSet.getString([3]) [0 seconds]
[19-07-23 04:44:29:255 PDT] TableRow.appendTableCell([Comissão de Vendas Kapten]) [0.001 seconds]
[19-07-23 04:44:29:256 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:257 PDT] Logger.log([Col: 3, []]) [0 seconds]
[19-07-23 04:44:29:258 PDT] Logger.log([col == 3: 3, []]) [0 seconds]
[19-07-23 04:44:29:258 PDT] JdbcResultSet.getString([4]) [0 seconds]
[19-07-23 04:44:29:259 PDT] TableRow.appendTableCell([129.82999999999998]) [0.001 seconds]
[19-07-23 04:44:29:260 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:261 PDT] Logger.log([Col: 4, []]) [0 seconds]
[19-07-23 04:44:29:262 PDT] Logger.log([col == 4: 4, []]) [0 seconds]
[19-07-23 04:44:29:262 PDT] JdbcResultSet.getString([5]) [0 seconds]
[19-07-23 04:44:29:263 PDT] TableRow.appendTableCell([0]) [0.001 seconds]
[19-07-23 04:44:29:264 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:265 PDT] Logger.log([Col: 5, []]) [0 seconds]
[19-07-23 04:44:29:266 PDT] Logger.log([Col: 6, []]) [0 seconds]
[19-07-23 04:44:29:266 PDT] JdbcResultSet.next() [0 seconds]
[19-07-23 04:44:29:267 PDT] Table.appendTableRow() [0 seconds]
[19-07-23 04:44:29:268 PDT] Logger.log([Col: 0, []]) [0 seconds]
[19-07-23 04:44:29:268 PDT] Logger.log([Col: 1, []]) [0 seconds]
[19-07-23 04:44:29:269 PDT] Logger.log([Col: 2, []]) [0 seconds]
[19-07-23 04:44:29:270 PDT] Logger.log([col == 2: 2, []]) [0 seconds]
[19-07-23 04:44:29:270 PDT] JdbcResultSet.getString([3]) [0 seconds]
[19-07-23 04:44:29:271 PDT] TableRow.appendTableCell([Comissão de Vendas Uber]) [0.001 seconds]
[19-07-23 04:44:29:272 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:273 PDT] Logger.log([Col: 3, []]) [0 seconds]
[19-07-23 04:44:29:274 PDT] Logger.log([col == 3: 3, []]) [0 seconds]
[19-07-23 04:44:29:274 PDT] JdbcResultSet.getString([4]) [0 seconds]
[19-07-23 04:44:29:275 PDT] TableRow.appendTableCell([252.1]) [0.001 seconds]
[19-07-23 04:44:29:277 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:277 PDT] Logger.log([Col: 4, []]) [0 seconds]
[19-07-23 04:44:29:278 PDT] Logger.log([col == 4: 4, []]) [0 seconds]
[19-07-23 04:44:29:279 PDT] JdbcResultSet.getString([5]) [0 seconds]
[19-07-23 04:44:29:280 PDT] TableRow.appendTableCell([0]) [0.001 seconds]
[19-07-23 04:44:29:281 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:281 PDT] Logger.log([Col: 5, []]) [0 seconds]
[19-07-23 04:44:29:282 PDT] Logger.log([Col: 6, []]) [0 seconds]
[19-07-23 04:44:29:283 PDT] JdbcResultSet.next() [0 seconds]
[19-07-23 04:44:29:284 PDT] Table.appendTableRow() [0 seconds]
[19-07-23 04:44:29:284 PDT] Logger.log([Col: 0, []]) [0 seconds]
[19-07-23 04:44:29:285 PDT] Logger.log([Col: 1, []]) [0 seconds]
[19-07-23 04:44:29:286 PDT] Logger.log([Col: 2, []]) [0 seconds]
[19-07-23 04:44:29:286 PDT] Logger.log([col == 2: 2, []]) [0 seconds]
[19-07-23 04:44:29:287 PDT] JdbcResultSet.getString([3]) [0 seconds]
[19-07-23 04:44:29:288 PDT] TableRow.appendTableCell([Portagens]) [0.001 seconds]
[19-07-23 04:44:29:289 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:289 PDT] Logger.log([Col: 3, []]) [0 seconds]
[19-07-23 04:44:29:290 PDT] Logger.log([col == 3: 3, []]) [0 seconds]
[19-07-23 04:44:29:290 PDT] JdbcResultSet.getString([4]) [0 seconds]
[19-07-23 04:44:29:291 PDT] TableRow.appendTableCell([0]) [0 seconds]
[19-07-23 04:44:29:292 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:293 PDT] Logger.log([Col: 4, []]) [0 seconds]
[19-07-23 04:44:29:293 PDT] Logger.log([col == 4: 4, []]) [0 seconds]
[19-07-23 04:44:29:294 PDT] JdbcResultSet.getString([5]) [0 seconds]
[19-07-23 04:44:29:295 PDT] TableRow.appendTableCell([6.75]) [0 seconds]
[19-07-23 04:44:29:295 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:296 PDT] Logger.log([Col: 5, []]) [0 seconds]
[19-07-23 04:44:29:297 PDT] Logger.log([Col: 6, []]) [0 seconds]
[19-07-23 04:44:29:297 PDT] JdbcResultSet.next() [0 seconds]
[19-07-23 04:44:29:298 PDT] Table.appendTableRow() [0 seconds]
[19-07-23 04:44:29:298 PDT] Logger.log([Col: 0, []]) [0 seconds]
[19-07-23 04:44:29:299 PDT] Logger.log([Col: 1, []]) [0 seconds]
[19-07-23 04:44:29:299 PDT] Logger.log([Col: 2, []]) [0 seconds]
[19-07-23 04:44:29:300 PDT] Logger.log([col == 2: 2, []]) [0 seconds]
[19-07-23 04:44:29:300 PDT] JdbcResultSet.getString([3]) [0 seconds]
[19-07-23 04:44:29:301 PDT] TableRow.appendTableCell([Consumo de Combustível]) [0.001 seconds]
[19-07-23 04:44:29:302 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:303 PDT] Logger.log([Col: 3, []]) [0 seconds]
[19-07-23 04:44:29:303 PDT] Logger.log([col == 3: 3, []]) [0 seconds]
[19-07-23 04:44:29:304 PDT] JdbcResultSet.getString([4]) [0 seconds]
[19-07-23 04:44:29:305 PDT] TableRow.appendTableCell([0]) [0 seconds]
[19-07-23 04:44:29:306 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:307 PDT] Logger.log([Col: 4, []]) [0 seconds]
[19-07-23 04:44:29:307 PDT] Logger.log([col == 4: 4, []]) [0 seconds]
[19-07-23 04:44:29:308 PDT] JdbcResultSet.getString([5]) [0 seconds]
[19-07-23 04:44:29:309 PDT] TableRow.appendTableCell([120.45760000000001]) [0 seconds]
[19-07-23 04:44:29:309 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:310 PDT] Logger.log([Col: 5, []]) [0 seconds]
[19-07-23 04:44:29:311 PDT] Logger.log([Col: 6, []]) [0 seconds]
[19-07-23 04:44:29:311 PDT] JdbcResultSet.next() [0 seconds]
[19-07-23 04:44:29:312 PDT] Table.appendTableRow() [0 seconds]
[19-07-23 04:44:29:313 PDT] Logger.log([Col: 0, []]) [0 seconds]
[19-07-23 04:44:29:313 PDT] Logger.log([Col: 1, []]) [0 seconds]
[19-07-23 04:44:29:314 PDT] Logger.log([Col: 2, []]) [0 seconds]
[19-07-23 04:44:29:314 PDT] Logger.log([col == 2: 2, []]) [0 seconds]
[19-07-23 04:44:29:315 PDT] JdbcResultSet.getString([3]) [0 seconds]
[19-07-23 04:44:29:316 PDT] TableRow.appendTableCell([Desconto de Combustível]) [0 seconds]
[19-07-23 04:44:29:317 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:317 PDT] Logger.log([Col: 3, []]) [0 seconds]
[19-07-23 04:44:29:318 PDT] Logger.log([col == 3: 3, []]) [0 seconds]
[19-07-23 04:44:29:318 PDT] JdbcResultSet.getString([4]) [0 seconds]
[19-07-23 04:44:29:319 PDT] TableRow.appendTableCell([11.262295934959347]) [0.001 seconds]
[19-07-23 04:44:29:320 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:321 PDT] Logger.log([Col: 4, []]) [0 seconds]
[19-07-23 04:44:29:321 PDT] Logger.log([col == 4: 4, []]) [0 seconds]
[19-07-23 04:44:29:322 PDT] JdbcResultSet.getString([5]) [0 seconds]
[19-07-23 04:44:29:323 PDT] TableRow.appendTableCell([0]) [0 seconds]
[19-07-23 04:44:29:324 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:324 PDT] Logger.log([Col: 5, []]) [0 seconds]
[19-07-23 04:44:29:325 PDT] Logger.log([Col: 6, []]) [0 seconds]
[19-07-23 04:44:29:325 PDT] JdbcResultSet.next() [0 seconds]
[19-07-23 04:44:29:326 PDT] Table.appendTableRow() [0 seconds]
[19-07-23 04:44:29:327 PDT] Logger.log([Col: 0, []]) [0 seconds]
[19-07-23 04:44:29:327 PDT] Logger.log([Col: 1, []]) [0 seconds]
[19-07-23 04:44:29:328 PDT] Logger.log([Col: 2, []]) [0 seconds]
[19-07-23 04:44:29:329 PDT] Logger.log([col == 2: 2, []]) [0 seconds]
[19-07-23 04:44:29:329 PDT] JdbcResultSet.getString([3]) [0 seconds]
[19-07-23 04:44:29:330 PDT] TableRow.appendTableCell([Garantia de Serviços Mínimos]) [0.001 seconds]
[19-07-23 04:44:29:331 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:332 PDT] Logger.log([Col: 3, []]) [0 seconds]
[19-07-23 04:44:29:332 PDT] Logger.log([col == 3: 3, []]) [0 seconds]
[19-07-23 04:44:29:332 PDT] JdbcResultSet.getString([4]) [0 seconds]
[19-07-23 04:44:29:334 PDT] TableRow.appendTableCell([0]) [0 seconds]
[19-07-23 04:44:29:334 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:335 PDT] Logger.log([Col: 4, []]) [0 seconds]
[19-07-23 04:44:29:335 PDT] Logger.log([col == 4: 4, []]) [0 seconds]
[19-07-23 04:44:29:336 PDT] JdbcResultSet.getString([5]) [0 seconds]
[19-07-23 04:44:29:337 PDT] TableRow.appendTableCell([290]) [0 seconds]
[19-07-23 04:44:29:337 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:338 PDT] Logger.log([Col: 5, []]) [0 seconds]
[19-07-23 04:44:29:339 PDT] Logger.log([Col: 6, []]) [0 seconds]
[19-07-23 04:44:29:339 PDT] JdbcResultSet.next() [0 seconds]
[19-07-23 04:44:29:340 PDT] Table.appendTableRow() [0 seconds]
[19-07-23 04:44:29:341 PDT] Logger.log([Col: 0, []]) [0 seconds]
[19-07-23 04:44:29:341 PDT] Logger.log([Col: 1, []]) [0 seconds]
[19-07-23 04:44:29:342 PDT] Logger.log([Col: 2, []]) [0 seconds]
[19-07-23 04:44:29:342 PDT] Logger.log([col == 2: 2, []]) [0 seconds]
[19-07-23 04:44:29:343 PDT] JdbcResultSet.getString([3]) [0 seconds]
[19-07-23 04:44:29:344 PDT] TableRow.appendTableCell([Pagamento Bluwalk Autonomo]) [0 seconds]
[19-07-23 04:44:29:345 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:345 PDT] Logger.log([Col: 3, []]) [0 seconds]
[19-07-23 04:44:29:346 PDT] Logger.log([col == 3: 3, []]) [0 seconds]
[19-07-23 04:44:29:346 PDT] JdbcResultSet.getString([4]) [0 seconds]
[19-07-23 04:44:29:347 PDT] TableRow.appendTableCell([0]) [0 seconds]
[19-07-23 04:44:29:348 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:349 PDT] Logger.log([Col: 4, []]) [0 seconds]
[19-07-23 04:44:29:349 PDT] Logger.log([col == 4: 4, []]) [0 seconds]
[19-07-23 04:44:29:350 PDT] JdbcResultSet.getString([5]) [0 seconds]
[19-07-23 04:44:29:351 PDT] TableRow.appendTableCell([156.36]) [0.001 seconds]
[19-07-23 04:44:29:352 PDT] TableCell.setAttributes([{FOREGROUND_COLOR=#000000, BOLD=false}]) [0 seconds]
[19-07-23 04:44:29:352 PDT] Logger.log([Col: 5, []]) [0 seconds]
[19-07-23 04:44:29:353 PDT] Logger.log([Col: 6, []]) [0 seconds]
[19-07-23 04:44:29:354 PDT] JdbcResultSet.next() [0 seconds]
[19-07-23 04:44:29:354 PDT] JdbcResultSet.close() [0 seconds]
[19-07-23 04:44:29:354 PDT] JdbcStatement.close() [0 seconds]
[19-07-23 04:44:29:381 PDT] JdbcConnection.close() [0.027 seconds]
[19-07-23 04:44:29:382 PDT] console.log([GSCRIPT after insertTableLedger, []]) [0 seconds]
[19-07-23 04:44:29:384 PDT] Body.replaceText([InsertTableLedger, ]) [0.001 seconds]
[19-07-23 04:44:29:384 PDT] console.log([GSCRIPT after body.replaceText, []]) [0 seconds]
[19-07-23 04:44:29:483 PDT] Document.saveAndClose() [0.098 seconds]
[19-07-23 04:44:29:483 PDT] console.log([GSCRIPT after realDoc.saveAndClose(), []]) [0 seconds]
[19-07-23 04:44:29:483 PDT] Document.getId() [0 seconds]
[19-07-23 04:44:29:484 PDT] console.log([GSCRIPT after var fileId, []]) [0 seconds]
[19-07-23 04:44:29:484 PDT] console.log([GSCRIPT exportPDF, []]) [0 seconds]
[19-07-23 04:44:29:541 PDT] DocumentApp.openById([]) [0.056 seconds]
[19-07-23 04:44:29:541 PDT] console.log([GSCRIPT after var docFile, []]) [0 seconds]
[19-07-23 04:44:29:633 PDT] Document.getAs([application/pdf]) [0.091 seconds]
[19-07-23 04:44:29:634 PDT] console.log([GSCRIPT after var docFilePdf, []]) [0 seconds]
[19-07-23 04:44:29:709 PDT] Document.getName() [0.074 seconds]
[19-07-23 04:44:29:710 PDT] Blob.setName([Driver .pdf]) [0.001 seconds]
[19-07-23 04:44:29:710 PDT] console.log([GSCRIPT after docFilePdf.setName, []]) [0 seconds]
[19-07-23 04:44:29:712 PDT] Blob.getName() [0 seconds]
[19-07-23 04:44:29:712 PDT] Blob.getContentType() [0 seconds]
[19-07-23 04:44:32:628 PDT] DriveApp.createFile([Blob]) [2.916 seconds]
[19-07-23 04:44:32:628 PDT] console.log([GSCRIPT after var file, []]) [0 seconds]
[19-07-23 04:44:32:629 PDT] File.getId() [0 seconds]
[19-07-23 04:44:32:629 PDT] console.log([GSCRIPT after var filePDFId, []]) [0 seconds]
[19-07-23 04:44:32:629 PDT] console.log([GSCRIPT moveFileId, []]) [0 seconds]
[19-07-23 04:44:32:760 PDT] DriveApp.getFileById([]) [0.13 seconds]
[19-07-23 04:44:32:760 PDT] console.log([GSCRIPT var file, []]) [0 seconds]
[19-07-23 04:44:32:890 PDT] DriveApp.getFileById([]) [0.129 seconds]
[19-07-23 04:44:32:891 PDT] File.getParents() [0 seconds]
[19-07-23 04:44:32:995 PDT] FolderIterator.next() [0.103 seconds]
[19-07-23 04:44:32:996 PDT] console.log([GSCRIPT var sourceFolder, []]) [0 seconds]
[19-07-23 04:44:33:153 PDT] DriveApp.getFolderById([]) [0.156 seconds]
[19-07-23 04:44:33:153 PDT] console.log([GSCRIPT var parentFolder, []]) [0 seconds]
[19-07-23 04:44:33:155 PDT] Folder.getFolders() [0.001 seconds]
[19-07-23 04:44:33:155 PDT] console.log([GSCRIPT var folders, []]) [0 seconds]
[19-07-23 04:44:33:292 PDT] FolderIterator.hasNext() [0.136 seconds]
[19-07-23 04:44:33:293 PDT] console.log([GSCRIPT count === 0, []]) [0 seconds]
[19-07-23 04:44:33:439 PDT] DriveApp.getFileById([]) [0.146 seconds]
[19-07-23 04:44:33:440 PDT] console.log([GSCRIPT after var docFileAsFile, []]) [0 seconds]
[19-07-23 04:44:33:548 PDT] DriveApp.getFolderById([]) [0.107 seconds]
[19-07-23 04:44:34:216 PDT] Folder.createFolder([]) [0.668 seconds]
[19-07-23 04:44:34:217 PDT] console.log([GSCRIPT after var createdFolder, []]) [0 seconds]
[19-07-23 04:44:34:217 PDT] console.log([GSCRIPT exportPDF -> moveFileId - create folder for nif: , []]) [0 seconds]
[19-07-23 04:44:34:218 PDT] File.getId() [0 seconds]
[19-07-23 04:44:34:917 PDT] Folder.addFile([Driver .pdf]) [0.698 seconds]
[19-07-23 04:44:34:917 PDT] console.log([GSCRIPT after createdFolder.addFile(file), []]) [0 seconds]
[19-07-23 04:44:34:918 PDT] File.getId() [0 seconds]
[19-07-23 04:44:35:477 PDT] Folder.removeFile([Driver]) [0.56 seconds]
[19-07-23 04:44:35:478 PDT] console.log([GSCRIPT after sourceFolder.removeFile(docFileAsFile), []]) [0 seconds]
[19-07-23 04:44:35:479 PDT] File.getId() [0 seconds]
[19-07-23 04:44:35:920 PDT] Folder.removeFile([Driver .pdf]) [0.441 seconds]
[19-07-23 04:44:35:920 PDT] console.log([GSCRIPT after sourceFolder.removeFile(file), []]) [0 seconds]
[19-07-23 04:44:35:921 PDT] console.log([GSCRIPT after moveFileId, []]) [0 seconds]
[19-07-23 04:44:35:921 PDT] console.log([GSCRIPT after var pdf, []]) [0 seconds]
[19-07-23 04:44:35:921 PDT] console.log([sendByEmail, []]) [0 seconds]
[19-07-23 04:44:36:059 PDT] DriveApp.getFileById([]) [0.137 seconds]
[19-07-23 04:44:36:579 PDT] MailApp.getRemainingDailyQuota() [0.519 seconds]
[19-07-23 04:44:36:580 PDT] File.getAs([application/pdf]) [0.001 seconds]
[19-07-23 04:44:36:845 PDT] Blob.getName() [0 seconds]
[19-07-23 04:44:36:851 PDT] Blob.getBytes() [0.005 seconds]
[19-07-23 04:44:36:854 PDT] Blob.getName() [0 seconds]
[19-07-23 04:44:36:854 PDT] Blob.getContentType() [0 seconds]
[19-07-23 04:44:37:613 PDT] GmailApp.sendEmail([]) [1.031 seconds]
[19-07-23 04:44:37:613 PDT] console.log([after MailApp.getRemainingDailyQuota(), []]) [0 seconds]
[19-07-23 04:44:37:614 PDT] console.log([GSCRIPT after sendByEmail, []]) [0 seconds]
[19-07-23 04:44:37:614 PDT] console.log([END GSCRIPT generateDriverPaymentExtract, []]) [0 seconds]
[19-07-23 04:44:37:614 PDT] console.log([========================================, []]) [0 seconds]
[19-07-23 04:44:37:616 PDT] Execution succeeded [16.378 seconds total runtime]

Edited 2nd time: G Suite Business - account


Have a look at the Drive Limit errors. I suspect that you are exceeding the rate limit (e.g. the limit for writing documents or exporting to PDF). You might either be exceeding the maximum allowed quota or the your quota might be restricted by the admin settings. The admin is able to see the quotas for each API in the Google Cloud Platform. You should be able to see in the execution manuscript which step throws you the error, and which limit exactly is exceeded.

In any case, I suggest you to implement the suggested actions - that is to either batch your requests or use an exponential backoff.