Reputation: 11
Hi I have a syntax error on a GoogleScript. this is my first script ever so I'm not really sure why is not working. The idea is to pick up information from a google sheet and create a label from a doc template and storage it in a folder
function readSheet() {
const labelFolder = DriveApp.getFolderById("1NTnJgjCewcFcrtMsl5DtRgrvFUNCdsvt");
const docFile = DriveApp.getFileById("1pRy9BLDuDka7-9PKnHGgO1AtgpoWIY45t7ypVhXXM8I");
const sheet = SpreadsheetApp.gettActiveSpreadSheet().getSheetByName("test");
const data = sheet.getRange(2,1,sheet.getLastRow()-1,10).getValues();
data.forEach(row => {
shippinglabels(row [5],row [6],row [8],docFile,labelFolder);
});
}
function shippinglabels(user,address,package,docFile,labelFolder) {
const labelFile = docFile.makeCopy(labelFolder);
const tempDocFile = DocumentApp.openById(labelFile.getId());
const body = tempDocFile.getBody();
body.replaceText("{user}", user);
body.replaceText("{address}", address);
body.replaceText("{package}", package);
tempDocFile.setName(user);
tempDocFile.saveAndClose();
}
Thanks
Upvotes: 0
Views: 539
Reputation: 11
I change the forEach form this:
data.forEach(row => {
shippinglabels(row [5],row [6],row [8],docFile,labelFolder);
});
To this:
data.forEach(function(row) {
shippinglabels(row [5],row [6],row [8],docFile,labelFolder);
});
and did the job.
Thanks for the help
Upvotes: 1
Reputation: 201378
Please modify as follows and test it again.
const sheet = SpreadsheetApp.gettActiveSpreadSheet().getSheetByName("test");
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("test");
gettActiveSpreadSheet()
is getActiveSpreadsheet()
.Upvotes: 1