lundi 27 mars 2023

run apps script based on first column value

completely new to Apps script; I did not find anything on the web, so please forgive me if it was already asked.

I have a spreadsheet in which, in the first column, there are checkboxes that can be true or false. I would like to run a script only on the rows that have the true checkbox. Here's the script (which is not running, it is just returning the first row).

function prova() {
const modello = DriveApp.getFileById('XXXX');
const cartellaword = DriveApp.getFolderById('XXXX');
const cartellapdf = DriveApp.getFolderById('XXXX');
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('automazione');
const rows = sheet.getDataRange().getValues();

rows.forEach(function(row, column) {
if (column[0] = true) {
const copy = modello.makeCopy(`${row[1]} - prova`, cartellaword);
const doc = DocumentApp.openById(copy.getId());
const body = doc.getBody();
const oggi = Utilities.formatDate(new Date(), "GMT", "dd/MM/yyyy");
const pdf = doc.getAs(MimeType.PDF);

body.replaceText('{oggi}', oggi);
body.replaceText('{nome}', row[1]);
body.replaceText('{datanascita}', row[2]);

doc.saveAndClose();
cartellapdf.createFile(pdf).setName(`${row[1]} - prova`)
}

})

}`

I tried to use: if (column[0] === true { /// run script } if (index[0] = true { /// run script }

Right now, the script works but it creates a PDF replacing only the first row (cell A1 is empty). I expected it to work for every rows which first cell (B1, C1, D1...) has the true checkbox.




Aucun commentaire:

Enregistrer un commentaire