Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 days ago.
Improve this question
we have a mistake in our code, could you pls check it ant tell us what we have to fix so it could run pls
ps : we are looking to send an email to the referent concerned.
//****GLOBALS****
var SpreadsheetID = "1y-EEf6F_mqxKjrsV_4mjTtQ4uxrJRV3ZErLBj_wkF_";
var SheetName = "Plan de Production ESAT Jemmapes";
function sendEmails() {
var recipient = "contact#lecadeaufrancais.fr";
var subject = "Test";
var message = "L'expédition est prête";
var commercial = sheet.getRange(3, 3).getValue();
switch (commercial) {
case "Alexis":
recipient = "clients#lecadeaufrancais.fr";
break;
case "Aïssa":
recipient = "entreprises#lecadeaufrancais.fr";
break;
case "Alfred":
recipient = "contact#lecadeaufrancais.fr";
break;
case "Elias":
recipient = "clients#lecadeaudentreprises.fr";
break;
default:
recipient = "";
}
if (sheet.getRange(6, 6).getValue() == true) {
subject = sheet.getRange(3, 5).getValue();
message = sheet.getRange(5, 5).getValue();
MailApp.sendEmail(recipient, subject, message);
}
SpreadsheetApp.getActiveSheet().toast("L'e-mail a été envoyé avec succès !", "Information", 5);
}
Alexis
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 months ago.
Improve this question
I have a google spreadsheet with many sheets which is used for requirement gathering. the stakeholder fills the data in every sheet
Now, some fields in each spreadsheet are very critical, hence we plan to highlight in some manner and the validation to take place
Once a sheet is filled the stakeholder will click on a button
This button will check if the mandatory fields are filled
If those cells are empty, a toast notification will pop up mentioning what is to be filled along with highlighting the cells in red color
After the stakeholder fills the info, hits validate button again, the same check happens and colors the cell background to white and display another toast pop up if all is ok.
I have following data in the google sheet
I wrote this apps script to have the validation stated in the above 4 points, as I am new to google apps script, I am facing difficulty with some bits of it
function toastMessageTitle() {
var sheet = SpreadsheetApp.getActive();
var rg1= sheet.getRange('B2');
var rg1_lbl = sheet.getRange('A2').getValue();
var rg2 = sheet.getRange('B5')
var rg2_lbl = sheet.getRange('A5').getValue();
var rg3 = sheet.getRange('B8')
var rg3_lbl = sheet.getRange('A8').getValue();
if (rg1.isBlank() && rg2.isBlank() && rg3.isBlank())
{ SpreadsheetApp.getActive().toast("Please fill - " + rg1_lbl+ ", " + rg2_lbl + ", " + rg3_lbl , "⚠️ Unfilled data",10);
rg1.setBackgroundColor("red");
rg2.setBackgroundColor("red");
rg3.setBackgroundColor("red");
}
else
{ SpreadsheetApp.getActive().toast("All filled", "Thank you",10);
}
}
Please help how can I get the validation done.
Here is a script you can use to achieve this:
function toastMessageTitle() {
var sheet = SpreadsheetApp.getActive();
var rg1= sheet.getRange('B2');
//var rg1_lbl = sheet.getRange('A2').getValue();
var rg2 = sheet.getRange('B5')
//var rg2_lbl = sheet.getRange('A5').getValue();
var rg3 = sheet.getRange('B8')
//var rg3_lbl = sheet.getRange('A8').getValue();
var ranges = [rg1, rg2, rg3];
var unfilled = [];
for(var range of ranges) {
if(range.isBlank()) {
unfilled.push(range.offset(0,-1).getValue())
range.setBackground('red');
} else {range.setBackground(null)};
}
if(unfilled.length == 0) SpreadsheetApp.getActive().toast("All filled", "Thank you",10);
else {
unfilled = unfilled.join(", ");
SpreadsheetApp.getActive().toast("Please fill - " + unfilled, "⚠️ Unfilled data",10);
}
}
This script simply goes through the different ranges, checks if they are blank, and then proceeds accordingly. If none of the cells are blank (ie the unfilled array has nothing in it), it shows the success message.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
I need to get the data filtered by month and year with dates in column A.
I tried something like this, but have a problem with the date formatting
function testMonthYear() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ss.getSheetByName("test");
var data = sheet.getDataRange().getValues();
Logger.log("data : " + JSON.stringify(data) +" " + data.length)
var filteredData = data.filter(function(r) {return Utilities.formatDate(r[0],"GMT+2",'MMMMyyyy' == "December2021")});
Logger.log("filteredData : " + filteredData + " " + filteredData.length )
}
Here's a simple test sheet :
https://docs.google.com/spreadsheets/d/1P58YMZZ5VrVCrTR8huhhhnmsOMZvKnzRqEqua2dICpo/edit#gid=0
In your script, how about the following modification?
From:
var filteredData = data.filter(function(r) {return Utilities.formatDate(r[0],"GMT+2",'MMMMyyyy' == "December2021")});
To:
var filteredData = data.filter(function (r) { return Utilities.formatDate(r[0], "GMT+2", 'MMMMyyyy') == "December2021" });
or
var filteredData = data.filter(r => Utilities.formatDate(r[0], "GMT+2", 'MMMMyyyy') == "December2021");
Utilities.formatDate(r[0],"GMT+2",'MMMMyyyy' == "December2021") is modified to Utilities.formatDate(r[0], "GMT+2", 'MMMMyyyy') == "December2021".
Reference:
filter()
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a script that was provided by someone on here that is intended to be used to retrieve the URL of the latest file in a drive folder. However, the script only works up to having the link in the logger, and not actually posting it into a cell.
Therefore, how can I have it post to a spreadsheet? This is the script I got, and I actually want it to post the URL in Column5 based on a value of Column4. If Column4 value is "YES" the link will be posted but if it is "NO" in column4 the it will simply be empty.
var files = DriveApp.getFolderById(folderId).getFiles();
var fileObj = [];
while (files.hasNext()) {
var file = files.next();
fileObj.push({url: file.getUrl(), date: file.getDateCreated()});
}
fileObj.sort(function(a, b) {return new Date(b.date) - new Date(a.date)});
return fileObj[0].url;
}
function myFunction() {
var folderId = "###";
var lastFileUrl = getLatestFile(folderId);
Logger.log(lastFileUrl)
}
function getLatestFile(folderId) {
var files = DriveApp.getFolderById(folderId).getFiles();
var fileObj = [];
while (files.hasNext()) {
var file = files.next();
fileObj.push({url: file.getUrl(), date: file.getDateCreated()});
}
fileObj.sort(function(a, b) {return new Date(b.date) - new Date(a.date)});
return fileObj[0].url;
}
function putInSS(ssid,sheetname,folderId) {
var ss=SpreadsheetApp.openById(ssid);
var sh=ss.getSheetByName('sheetname');
var rg=sh.getDataRange();
var rg5=sh.getRange(1,5,sh.getLastRow(),1);
var v5=rg5.getValues();
var v=rg.getValues();
var url=getLastestFile(folderId);
v.forEach(function(r,i){
if(r[3]=='YES') {
v5[i]=url;
}
if(r[3]=='NO') {
v5[i]='';
}
});
rg5.setValues(v5)
}
enter code here
EDIT: more information. Every special-ed binder requires a review to check for compliance. The review is a 60 plus questionnaire that we turned into a Google form for ease of communication and also to keep data in our district about numbers of binders that are or are not compliant. Well there are really three levels of errors that can occur which need different fixes, from paperwork, to re-training. The goal is that when the form is filled out if an email would be sent depending on what level(s) of error occurred. So if I answered "no" to any question between 6 and 9 then I would get an email stating that a level 1 error was made. Same for level 2 and for level 3 errors. The issue I'm having is that I can only get an email to work when only one error was made or all errors were made. I made a test form, with less questions to test out the coding: https://forms.gle/sM1qWRE7MykVT1Cq6
Also, here is a link to form response spreadsheet so you can get an idea of what I'm trying to accomplish. https://docs.google.com/spreadsheets/d/1YLmIrFO1AK0i0BujwIL1sFVLHuopV0y-cztcykFfpTg/edit?usp=sharing
Finally, here is the code I used for the sample:
function sendEmail() {
var ss = SpreadsheetApp.getActive();
var responses = ss.getSheetByName('Sheet1');
var data = responses.getRange(2,1,responses.getLastRow()
-1,7).getValues();
Logger.log(data);
data.forEach(function(row,i) {
var email = row[1];
var answer = row[2];
var replied = row[6];
var level1 = row[3];
var level2= row[4];
var level3 = row[5];
if (replied == '') {
//if (level1 == 'No' && level2 =='No' && level3 == 'No') {
//var body = "The Sped compliance form submitted shows levels 1,2,
and 3 erorrs. Please review check the district review for further insructions";
//}
if (level1 == 'No'){
Logger.log('yes response');
Logger.log(email);
var body = "The SPED compliance check has found a Level 1 error, please see documentation to fix errors.";
}
else if (level2 == 'No') {
Logger.log("no Response");
Logger.log(email);
var body = "The SPED compliance check has found a Level 2 error, please see documentation to fix errors";
}
else if (level3 == 'No'){
var body = "The SPED compliance check has found a Level 3 error, please see documentation to fix errors";
}
else {
}
var subject = "thank you for submitting your form";
GmailApp.sendEmail(email, subject, body);
var d = new Date();
responses.getRange(i + 2,7).setValue(d);
}
});
If a person answers 'No' for any questions in 1-3 then it is a level 1 error, if a person answers 'No' to any questions in 6-9 it is a level 2 error, and if a person answers 'No' to any of the questions in 11-15 it is a level 3 error. I can a response email if there is only 1 error (level 1,2, or 3), however if a person chooses no to more than one set of responses then the code will not work. I'm new to this so I know I'm missing some detail, just not too sure how to get the logic to work.
I have tried adding a clause for if all levels are selected. It didn't work
What I would like to see is that if a person commits a level 1 and other level error that it would show both levels of error.
How about doing it with a counter instead of all those conditions? For example, depending on the Level:
Level 1: if the answer is No, Add 1
Level 2: if the answer is No, Add 10
Level 3: if the answer is No, Add 100
This way you would only need 3 conditions: I edited my code according to yours:
data.forEach(function(row,i, responses) {
var counter = 0;
var email = row[1];
var answer = row[2];
var replied = row[6];
var level1 = row[3];
var level2= row[4];
var level3 = row[5];
if (level1 == 'No'){
counter += 1;
}
if (level2 == 'No'){
counter += 10;
}
if (level3 == 'No'){
counter += 100;
}
if (counter < 10){
var body = "The SPED compliance check has found a Level 1 error, please see documentation to fix errors.";
} else if (counter >= 10 && counter < 100){
var body = "The SPED compliance check has found a Level 2 error, please see documentation to fix errors";
} else {
var body = "The SPED compliance check has found a Level 3 error, please see documentation to fix errors";
}
var subject = "thank you for submitting your form";
GmailApp.sendEmail(email, subject, body);
var d = new Date();
responses.getRange(i + 2,7).setValue(d);
});
However, it would be nice to see the rest of your code to figure out how it is developed.
I currently have a working Google script that reads in the values on a dashboard in Google Sheets for swimming pool chemical monitoring. People will submit a form and if those numbers are greater than or less than a set number, it will send an email with a specific message.
This works fine but if there are multiple numbers that are off, I will receive multiple emails which gets annoying.
I am looking for one simple, clean output instead of multiple emails.
Here is part of my code (the rest is the same just different pools).
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
//----vvvvvPool
var IDPpHReading = sheet.getRange('A6:A7').getValue();
var IDPpHTest = sheet.getRange('B6:B7').getValue();
var IDPORP = sheet.getRange('A9:A10').getValue();
var IDPSetPoint = sheet.getRange('B9:B10').getValue();
var IDPCL = sheet.getRange('A12:A13').getValue();
var IDP_Filter1_INF = sheet.getRange('A16:A17').getValue();
var IDP_Filter1_EFF = sheet.getRange('B16:B17').getValue();
var IDP_Filter2_INF = sheet.getRange('A20:A21').getValue();
var IDP_Filter2_EFF = sheet.getRange('B20:B21').getValue();
// insert email here
var emailAddress = "pseudoMcFakeEmail#Battlecruiser.com";
//-------------------- IDP pH
if (IDPpHReading > 7.8) {
var subject = "High pH Reading IDP";
var message = " An Aquatic Specialist recently logged a chemical reading that was too high for the Indoor Pool. Please check the situation asap.";
MailApp.sendEmail(emailAddress, subject, message);
}
else if (IDPpHReading < 7.2) {
var subject = "Low pH Reading IDP";
var message = " An Aquatics Specialist recently logged a chemical reading that was too low for the Indoor Pool. Please check the situation asap.";
MailApp.sendEmail(emailAddress, subject, message);
}
if (IDPpHTest > 7.8) {
var subject = "High pH Test IDP";
var message = " An Aquatics Specialist recently logged a chemical reading that was too high for the Indoor Pool. Please check the situation asap.";
MailApp.sendEmail(emailAddress, subject, message);
}
else if (IDPpHTest < 7.2) {
var subject = "Low pH Test IDP";
var message = " An Aquatics Specialist recently logged a chemical reading that was too low for the Indoor Pool. Please check the situation asap.";
MailApp.sendEmail(emailAddress, subject, message);
}
};
My go for this would be to make each message unique :
var message 1;
var message 2;
etc
and then have the email - MailApp.SendEmail(emailAddress,subject, message1+message2....);
But I feel like that is a sloppy way to do it.
I have had to do this a few times and what I usually do is use string concatenation to build the message and then send it:
var subject = "Abnormal pH Reading IDP";
var message = 'An Aquatics Specialist recently logged a chemical reading at the indoor pool and found:\n';
var needsCheck = false;
if (IDPpHReading > 7.8) {
var message = message + "\nA reading that was too high.";
var needsCheck = true;
}
else if (IDPpHReading < 7.2) {
var message = message + "\nA reading that was too low.";
var needsCheck = true;
}
if (IDPpHTest > 7.8) {
var message = message + "\nA test that was too high.";
var needsCheck = true;
}
else if (IDPpHTest < 7.2) {
var message = message + "\nA test that was too low.";
var needsCheck = true;
}
if (needsCheck){
var message = message + "\n\nPlease check the situation asap.";
MailApp.sendEmail(emailAddress, subject, message);
}