I am not a programmer. Through some online help I have been able to write a code that can send data from sheet into Slack channel but the problem right now is that it picks first cell from the range only. However, I want it to pick data from the most recent row
Sheet Context: A form is attached to this sheet and gets submissions, the purpose is that whenever someone submits form, a message gets posted on slack for the team to be notified
So, i want my code to pick data from most recent form submission. P.S my entire column is pre-filled with formula so need a way like VLOOKUP where it can see if one cell is blank then picks data from another column same row
function buildReport() {
const ss = SpreadsheetApp.getActive();
let data = ss.getSheetByName('Sheet1').getRange("AG9:AH999");
let payload = buildAlert(data);
sendAlert (payload);
}
function buildAlert(data) {
for (i=0 ; i<20 ; i++) {
newOrder = data .getvalue(i,1);
};
let payload = {
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":bell: *New Order Alert* :bell:"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": newOrder
}
},
]
};
return payload;
}
function sendAlert(payload) {
const webHook = "https://hooks.slack.com/services/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";//
var options = {
"method": "post",
"contentType" : "application/Json" ,
"muteHttpExceptions" : true ,
"payload" : JSON.stringify(payload)
};
try {
UrlFetchApp.fetch(webHook,options);
} catch(e) {
Logger.log(e);
}
}




