Hey there, I'm having a syntax error in my GoogleScript. This is actually my first script ever, so I'm a bit lost as to why it's not working. The main goal is to extract data from a Google sheet and use it to create labels based on a document template and then store them in a specific folder.
function readSheet() {
const labelFolder = DriveApp.getFolderById("1NTnJgjCewcFcrtMsl5DtRgrvFUNCdsvt");
const docFile = DriveApp.getFileById("1pRy9BLDuDka7-9PKnHGgO1AtgpoWIY45t7ypVhXXM8I");
const sheet = SpreadsheetApp.getActiveSpreadsheet().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!