简体   繁体   English

Google Apps 脚本。 JSON 到电子表格 - 结果太长(API 到表格)仅适用于 100 reg

[英]Google Apps Script. JSON to Spreadsheet - Result too long (API to Sheet) Work only with 100 reg

Good morning, I have made a Script that connects with an APi, it returns a JSON, I serialize it and complete an array with it.. then I paste it in a Google Spreadsheet, but it only works with 100 records.早上好,我制作了一个与 APi 连接的脚本,它返回一个 JSON,我对其进行序列化并用它完成一个数组。然后我将它粘贴到谷歌电子表格中,但它只适用于 100 条记录。 However if in the same Script, under the JSON my Google Drive makes it complete.但是,如果在同一个脚本中,在 JSON 下,我的 Google Drive 使它完整。 When I check the Logger it tells me the result is too long...当我检查记录器时,它告诉我结果太长......

My code.我的代码。

function getOT() {
  
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('OT');
  var url ='https://app.XXXXX.com/api/work_orders';
  var authorization=XXXXXXApi(XXX,'app.XXXXXX.com','/api/work_orders','GET','443');
  var Options ={
  "url": "https://app.XXXXXX.com/api/work_orders",
  "method": "GET",
  "timeout": 0,
  "headers": {  "Authorization": "Hawk id=\""+authorization.cID+"\", ts=\""+ authorization.cTS+"\", nonce=\""+authorization.cNONCE+"\", mac=\""+authorization.cHMAC+"\"",
  },
};

 var response = UrlFetchApp.fetch('https://app.XXXX.com/api/work_orders', Options);
 var array = [];
 var CC = response.getContentText();
 var datos = JSON.parse(CC);
 Logger.log (CC)

 for (var i = 0; i < datos.data.length ;i++) {
  array.push([datos.data[i]['wo_folio']],[datos.data[i]['description']],[datos.data[i]['personnel_description']],[datos.data[i]['items_log_description']])
  
 };
           
  for (var i = 0; i < datos.data.length ;i++){
     var startrow=2 + +i;
    sheet.getRange(startrow, 1).setValue(datos.data[i]['wo_folio']);
    sheet.getRange(startrow, 2).setValue(datos.data[i]['description']);
    sheet.getRange(startrow, 3).setValue(datos.data[i]['personnel_description']);
    sheet.getRange(startrow, 4).setValue(datos.data[i]['items_log_description']);
   }
 
DriveApp.createFile('XX.csv', CC); //copio el JSON a mi drive

}

The Logging output too large. Truncating output. Logging output too large. Truncating output. Logging output too large. Truncating output. message is not an error, it's just a notice. message 不是错误,它只是一个通知。 It simply doesn't show the entire data, only a subset.它根本不显示整个数据,只显示一个子集。 This means that the data is actually there but is not shown to you when using a single call.这意味着数据实际上存在,但在使用单个调用时不会显示给您。 Try logging the output inside a loop and print all the elements.尝试在循环中记录 output 并打印所有元素。

As for the TypeError: Cannot read property 'wo_folio' of undefined , it seems that this happens because you are modifying increasing the length property of datos.data :至于TypeError: Cannot read property 'wo_folio' of undefined ,似乎这是因为您正在修改增加datos.data的 length 属性:

const array = ['a', 'b']
array.length = 3
console.log(array) // outputs ['a', 'b', empty]

Notice that if I try to get the third element of array 2, you'll get undefined .请注意,如果我尝试获取数组 2 的第三个元素,您将得到undefined In a similar way, datos.data[i]['wo_folio'] will become undefined['wo_folio'] if iterated outside the original length, and thus the error is thrown.以类似的方式,如果在原始长度之外迭代, datos.data[i]['wo_folio']将变为undefined['wo_folio'] ,从而引发错误。 And just so you know, changing an array length via its length property is rarely used.正如您所知,很少使用通过其length属性更改数组长度。

I have put the size of the data, and I figure 100我已经放了数据的大小,我想 100

var CC = response.getContentText();
var datos = JSON.parse(CC);
var registros=datos.data;
Logger.log(registros.length);

[21-01-03 00:19:21:398 ART] 100.0.. but i have too many more... [21-01-03 00:19:21:398 ART] 100.0 .. 但我还有太多...

If I run the query from postman, it has more than 300 records.. it only happens when I query it from GAS如果我从 postman 运行查询,它有超过 300 条记录.. 只有当我从 GAS 查询它时才会发生

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM