I’ve been trying to automate sending messages when some of my reports are uploaded through a checkbox trigger on Gscript. (Idea being report is updated-> User check the checkbox -> message is sent to slack)
So far, I’ve been able to create the script to send the message to slack, and even reset my checkboxes at night. The only issue I have is with the trigger.
I’ve used onEdit as a trigger, on my three checkboxes (A1,B1,C1):
function onEdit(e) {
const as = e.source.getActiveSheet();
const cell = e.range.getA1Notation();
if(as.getName() == 'Sheet1' && cell.getRange('A1').ischecked() === true) {
SendSlackMessage1();
}
else if (as.getName() == 'Sheet1' && cell.getRange('B1').ischecked() === true) {
SendSlackMessage2();
}
else if (as.getName() == 'Sheet1' && cell.getRange('C1').ischecked() === true) {
SendSlackMessage3();
}}
As a reference here’s the function to send messages :
function SendSlackMessage1() {
const url = "https://hooks.slack.com/services/XXXXXXXXXXXXX";
const params = {
method: "post",
contentType: "application/json",
payload: JSON.stringify({
"text":"Report A has been uploaded"
})
}
const sendMsg = UrlFetchApp.fetch(url, params)
var respCode = sendMsg.getResponseCode()
Logger.log(sendMsg)
Logger.log(respCode)
}
(All of SendSlackmessages function are the same except for text (Report A/B/C), and I’ve already authorized the functions to run on google.
So obviously, I’m doing something wrong, but what ? my first guess would be that I’m not properly defining the e range, but I don’t know what to do next.
I’d be grateful if someone can give me a headstart or pointing me at where to look.
Thanks ! 😀