Please help me with the script I want to run when I check a specific checkbox in Google Sheets. It works for me when I put it with a button but it doesn’t work on tablets so I want to make it with a checkbox.
function sendExportedSheetAsPDFAttachment() {
let blob = getFileAsBlob("https://docs.google.com/spreadsheets/d/1FuTHRBQ0JRmo35kcrFBIhzjRXGTea3Xznek1lKE6xT0/export?format=pdf&scale=3");
blob.setName("ΘΕΛΩ ΕΧΩ ΕΘ.ΑΝΤΙΣΤΑΣΕΩΣ");
var message = {
to: "[email protected]",
subject: "ΘΕΛΩ ΕΧΩ ΕΘ.ΑΝΤΙΣΤΑΣΕΩΣ",
body: "Χαίρεται,nnΠαρακαλώ βρείτε συννημένη τη σημερινή παραγγελία.nnΕυχαριστώ,nΠαραγγελίες",
name: "ΕΘ.ΑΝΤΙΣΤΑΣΕΩΣ",
attachments: [blob.setName("ΘΕΛΩ ΕΧΩ ΕΘ.ΑΝΤΙΣΤΑΣΕΩΣ")]
}
MailApp.sendEmail(message);
}
and the other is related to the script above
function getFileAsBlob(exportUrl) {
let response = UrlFetchApp.fetch(exportUrl, {
muteHttpExceptions: true,
headers: {
Authorization: 'Bearer ' + ScriptApp.getOAuthToken(),
},
});
return response.getBlob();
}
Thank you very much.
It works for me when I put it with a button but it doesn’t work on tablets so I want to make it with a checkbox.
2
Answers
Running a Script When Checkbox Is Ticked
First Method
There are two ways to run a script when a checkbox is ticked. First, you can use the google sheets built-in
if
condition. To do this, paste the following into any empty cell. Make sure to replaceA1
with the location of your checkbox.This will run your function when the checkbox is ticked, and nothing when the checkbox is unticked.
Second Method
Paste the following code into the Google Apps Script where you have your functions, found on
Extensions > Apps Script
Once again, replace
A1
with the location of your checkbox.Make it an installable trigger