Reputation: 147
I like to modify this script to duplicate a single record as many times as I need into gsheets.
As of now my script below just posts a single record as intended.
Now I like to add a variable(quantity) and have the record posted(append) onto the sheet as many times as the quantity variable says.
function sendProductIDtoQRCodeSheet(fieldData){
var sheet = SpreadsheetApp.openById('1fUNWqzHosafsdafasdfas--B4').getSheetByName('LISTS');
var lRow = sheet.getLastRow();
var range = sheet.getRange("A1:A");
var value1 = fieldData.productId;
var value2 = fieldData.productName;
var joinedValues = value1 + " | " + value2;
sheet.appendRow([
fieldData.productId, joinedValues
]);
}
Upvotes: 0
Views: 39
Reputation: 6062
In order for you to achieve what you want, you can use a for
loop and a take a look at these methods since they can be of help:
getRange(row, column, numRows, numColumns)
- for getting the range with the given numbers of rows and columns;
setValues(values)
- for setting the values on the specified range for which they must match the dimensions of it;
You might also want to search similar questions here on Stack which can be of help.
Upvotes: 1
Reputation: 36
Is there a reason you can't use a loop?
Check the documentation for the sheet class. There's a method called insertRows(rowIndex, numRows) that could be what you're looking for. It inserts a number of blank rows equal to numRows at the index. You can just populate them after you make them.
Upvotes: 0