user2916405
user2916405

Reputation: 147

How can I duplicate value into Gsheets with apps script?

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

Answers (2)

ale13
ale13

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:

You might also want to search similar questions here on Stack which can be of help.

Upvotes: 1

William Spear
William Spear

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

Related Questions