I am trying to fetch XML by Google App Script and then passing these values to Google Sheets. Everything works fine for a few iterations. If I try more, I will exceed the maximum time of execution.
The code below results in an error message "Exceeded maximum execution time". If I lower a number of iteration (3), It will work. But I need to iterate through approximately 20K rows.
function myFunction(){
var url = '<<file name>>';
var bggXml = UrlFetchApp.fetch(url).getContentText();
var document = XmlService.parse(bggXml);
var root = document.getRootElement();
var now = new Date();
for(var i = 0; i <= 20; i++){
var shopitem = root.getChildren('SHOPITEM')[i];
var code = shopitem.getChild('CODE').getText();
var stock100 = shopitem.getChild('STOCK').getChild('WAREHOUSES').getChildren('WAREHOUSE')[0].getChild('VALUE').getText();
var stock801 = shopitem.getChild('STOCK').getChild('WAREHOUSES').getChildren('WAREHOUSE')[1].getChild('VALUE').getText();
SpreadsheetApp.getActiveSheet().getRange(1+i,1).setValue(code);
SpreadsheetApp.getActiveSheet().getRange(1+i,2).setValue(stock100);
SpreadsheetApp.getActiveSheet().getRange(1+i,3).setValue(stock801);
}
}
Feed structure
<SHOP>
<SHOPITEM>
<CODE>#SKU#</CODE>
<STOCK>
<WAREHOUSES>
<WAREHOUSE>
<NAME>Sklad 100</NAME>
<VALUE>"stock value"</VALUE>
</WAREHOUSE>
<WAREHOUSE>
<NAME>Sklad 801</NAME>
<VALUE>"stock value"</VALUE>
</WAREHOUSE>
</WAREHOUSES>
</STOCK>
</SHOPITEM>
</SHOP>
Any suggestion, what might be wrong?
Thank you very much