I wrote the following simple script (my script knowledge is limited) & I wrote this to send an automated email once my inventory hit below a certain threshold but I would like to change my subject line to be the variable of the low inventory item. The line I am struggling with is var subject. Would love some help!
`
function CheckSales() {
// Fetch the monthly sales
var monthSalesRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Parts").getRange("E9");
var monthSales = monthSalesRange.getValue();
// Check totals sales
if (monthSales < 21){
// Fetch the email address
var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getRange("B2");
var emailAddress = emailRange.getValues();
// Send Alert Email.
var message = 'Inventory has hit and/or is below minimum threshold for' + monthSales; // Second column
var subject = .query("C9");
MailApp.sendEmail("example@google.com", subject, message);
}
}`
I tried writing the query code but now that I have written that, I am met with: 9:08:07 AM Error Attempted to execute CheckSales, but could not save.