There is a script that receives data from the request. I send count - it means the number of parameters that must be obtained, and the parameters themselves in the following form: product1 productQuant1 , product2 productQuant2 , that is, in this case, count=2 . The task is to extract all parameters in a loop, referring to them by name, composed of product + i , where i is a loop variable. I tried concatenation, does not work.

 for (var i = 1; i <= count; i++) { var product = request.parameter.product + i; var productQuant = request.parameter.productQuant + i; sheet.appendRow([product, productQuant]); } 
  • Give an example request. - oshliaer
  • "https: / /script.google.com/macros/s/AKfycbxFZC9YPpG1-A_StZ583S0jtkmApNOEFclM8eKJ3bLB0zwiHN0/exec?product1=Americano&product2=Pizza&productQuant1 ** -cEPH144p2BPB1zWiHN0km4proc=pro1=Americano&product2=PH2BLB0zwiHN0km4ktkmApNOEFclM8ePJ1bAFNC2YPpG1-A_StZ583S0jtkmApNOEFclMs

1 answer 1

You will probably need to access the property of the object by its key. For example, for product you must call e.parameter['product' + (i + 1)]

 function doGet(e) { var count = e.parameter.count || 0; var values = []; for (var i = 0; i < count; i++) values.push([e.parameter['product' + (i + 1)], e.parameter[ 'productQuant' + (i + 1)]]); /* The sheet has to exist. var sheet = SpreadsheetApp.openById('ABC').getSheets()[0]; */ if(values.length) sheet.getRange(sheet.getLastRow() + 1, 1, values.length, values[0].length) .setValues(values); }