I have a Google sheet where our agents updated about the emails being sent and the responses received. If they send an email out, they will update the status as "Sent". If they get a response for the email sent, they will change the status to "Client not interested" or "send more details" or some other statuses based on the reply received from the drop-down.
We enter the date in a column by when we sent the email. From that day we wait for three days to get a reply and if it was not received, then the "sent" status should disappear from cell wherever it appears in the status column.
Basically if we did not receive any reply after 3 days from the date of sending the email, the status set as "Sent", should disappear which we understand as "no reply received" for the email sent.
I am not skilled with scripts. I need your help to add a script for this as we will be sending many emails everyday and automating this particular thing will help us a lot. Thanks in advance.
Best
Joe
Most likely you will want to utilize an onEdit trigger. ref
And you will have to set up data validation for The Status Column and that can be accomplished through the Data Menu.
Most well writtten onEdit functions are similar to this:
function onEdit(e) {//e is population by the triggers event object
const sh = e.range.getSheet();
if( sh.getName() == "your sheet name" && e.columnStart == "column number of status column" && e.range.rowStart > "header row" ) {
//enter the rest of your code in here and all other edits on this and other pages will not enter this code and be returned as quickly as possible
}
}
After you've learned a little more about how the onEdit work you may wish to reconsidered how you would like things to work because a good design is typically a compromise between the user interface and the complexity of the software.
Related
I'm not a technical person and need help on using apps script.
I have a sheet with 5 tabs (each sheet are exactly the same format of column headers)
Column B is a dropdown of 4 points of contact. E.g. John, Anna, Peter and Michelle
Goal: when a user selects a name from the dropdown, it will send an email to whoever was chosen.
subject and message can be a generic template for everyone
Can someone help me with a script I can copy and paste for this?
As it says in the comments, StackOverflow is not a coding writing service, but I will give you a couple of keys to achieve it by yourself.
What is the main point? We need to observe the changes on the sheet, and when it coincides with the cell that contains the email, we send the email to the one the value is in the cell.
We need to observe the changes on the sheet, how we achieve it? With an installable trigger we can capture edits events on the Sheet, as the change of the drop-down list.
Finally we need to filter the event and only attend to the ones that are in the cell or cells that contain the drop-down.
In this example I have the cell A1 with the drop-down of emails:
const sendEmailFromSheets = (e) => {
const range = e.range;
const email = e.value;
if( range.getA1Notation() === 'A1') {
MailApp.sendEmail(email,'Message from the Sheet', 'Body')
}
}
After this, we attach this function to an installable trigger with the source From spreadsheet and type On change.
With all of this, you should be able to change it to adapt it to your needs.
Documentation:
SpreadsheetApp
Event-driven Trigger
I have users subscribing to a mail service using google forms and they indicate how often they would like to receive an email, the value is recorded on a cell(ex.: every 1h, 2h ...).
I would like to loop through each user email and send a message based on the time they chose. Is there a way to do it with triggers?
Here is what I got so far:
function sendMail(){
for (i=2;i<=lastEmailRow;i++){
var currEmail = recipients.getRange(i, 2).getValue();
var currentTrigger = recipients.getRange(i, 3).getValue(); //how often
currentTrigger = currentTrigger.split(" ")[1];
MailApp.sendEmail(currEmail, "myEmail#sample.com", "Your Daily Mail",
{ htmlBody: HTML});
}
}
If your script is working fine (I'm not sure as lastEmailRow isn't defined on the question code) you have to make some design decisions, like if you will be using only one function or you will be using multiple functions, one for each frequency.
Depending on the above decision, then you could
create one time-driven trigger that runs very often, let say every hour
create several time-driven triggers, each with it's own settings.
In any case, you should include some conditions to control to whom send the email.
I'm making a website for school to connect students and teachers. Teachers fill out a Google Form asking for service (grading papers...) and it is connected to Google Spreadsheets. Then a student can see that Spreadsheet and sign up on a different Google Form to help the teacher, and that response is recorded in the same Google Spreadsheet. When the student submits his/her Google Form, I want the teacher to be notified by email that a student signed up to help them. How can I send that notification? And I don't want the notification to come from my own school address. Is that possible?
Here is the Google website: https://sites.google.com/fcpsschools.net/jmhsservicesignup/subjects/math
This is the code I have so far:
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Tutors
Signed Up");
var startRow = sheet.getLastRow(); // First row of data to process
var dataRange = sheet.getRange(startRow, 1, 1, 5)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[3]; // Second column
var tutor = row[0];
MailApp.sendEmail(emailAddress,"Tutor Request Filled",""+tutor+" has accepted your request to be tutored! Please notify"+tutor+" if anything changes.");
}
}
The getLastRow doesn't seem to work, and the email sends from my own address, not a Google forms notification if that is even possible.
If this is impossible I might just make the students send the email to the teacher, but I really want to automate the process. If you can think of a workaround, that would also be awesome.
Adding to what Sandy Good and Guilherme mentioned.
Here are a few more tips:
Not clear what data you're trying to get in your function. Are you trying to grab the data from the form submission? In that case you need to set up a trigger from the scripts menu, and connect it to the function (function needs to have an 'event' argument, usually called e).
function processFromSubmission(e) {//get data from e}
Apologies if you're not trying to do that. What happens when you Log sheet.getLastRow()?
Ask the school if they can get you another email address to use for this form, something like notifications#yourschool.edu. Follow the steps here to set up your alias. Do it for the gmail account that "owns" the spreadsheet these forms are sending data to.
Make sure your alias is set up properly. You should be able to see it in the "from" dropdown menu when you compose an email. Also try running the code Logger.log(GmailApp.getAliases()) and check the log to see that it's available.
Use GmailApp.sendEmail to send email, not MailApp.sendEmail. They're almost the same, but it looks like the MailApp version doesn't let you send from an alias. You can specify the 'replyTo' email as well if you want to set it to something else, like the student filling out the form or whatever (still not clear exactly what you're trying to set up!).
Send email like:
GmailApp.sendEmail(emailAddress, subject, body,
{replyTo: replyToEmailAddress_can_be_any_email,
from: 'notifications#yourschool.edu'
});
Note: your link didn't open.
I have created an application where I am collecting form responses from various users. I am getting responses with email id in responses spreadsheet. As I don't want to store data in spreadsheet so I am reading data trough responses. I am facing some challenges please guide.
Query 1
while using onFormSubmit(e) I am not able to read submitted form, given code is returning null:
var form = FormApp.getActiveForm();
Logger.log('usename:' + form.getId());
error " Cannot call method "getId" of null." although if I hard coded value of formid var form = FormApp.openById('<<form_id_xyz>>'); then it is working fine and I can read responses as well.
How can I get form responses for multiple users?
Query 2
getRespondentEmail(); is not working in my case. Even I use form id <<form_id_xyz>> and trying to get email id from responses which I have captured at the time of form submission form.setCollectEmail(true); I tried following code in onFormSubmit(e) function but dint get a result:
var formResponse=form.response;
Logger.log('email id of user: ' + formResponses.getRespondentEmail());
and another way:
Logger.log('email id of user: ' + form.getRespondentEmail());
and
Logger.log('email id of user: ' + e.values[1]);
nothing works for me. Kindly guide.
Query 1: Hope it's clear in my comment.
Query 2:
Sorry to say, I don't understand your second query problem completely.
However as per your requirement I am suggesting this code.
If you have created a form you should know the form id (I assume) so try this code.
var form=FormApp.openById('your form id here');
//this returns your form which you created//
var responses=form.getResponses();
/// this will give you all responses of your form as an array////
///iterate the array to get respondent email id///
for(var i = 0; i < responses.length; i++){
Logger.log(responses[i].getRespondentEmail());
}
I think it's important to note that at the present time the answer to your question is: You can get what they enter, but you cannot get their true verified Email Address. This is explained better in this question and one of the answers details some workarounds such as publishing form as a web script.
The accepted answer displays what email address the user has typed into the form. There is no authentication to this beyond it having an # symbol thus a user could type foofoo#zoomZoom.com and it would be viewed in the forms results and scripts.
What's annoying is that google IS capturing the user's true email address because if settings are set to Allow One Response Per User, then the user is limited to one submission -- regardless of what they put as their email account. I'm not sure why Google won't provide a method to view the submitter's login email address since it has been disclosed to the user that this will be disclosed.
Microsoft Forms does capture this.
I have had formemailer setup the same way for over a year and have never had this problem. I have not changed anything but now all of a sudden it has started sending all form responses with my email address in the from field. How do I fix this it has happened on 3 different forms that we have. Thanks
I think the problem you are seeing is due to issue 2004. Please star the issue to be notified of updates to it. FormEmailer is probably a victim of this bug
I've experienced this problem myself and I'm glad to say I know how to fix this, and it does involve some javascript coding.
If you're having emails sent to you that must mean you have set up an automatic trigger(time-driven) and you have set up the settings to send emails to your address (for testing, I assume?) If you have an email address column you want to send emails to, that should be the column in which a placeholder references.
To stop sending blank emails to yourself in the thousands, you have to adjust the code so that it knows when to trigger! The original code does not account for when to stop emailing on an automatic trigger.
Line 209: var status = c.fs.getRange(2,1,last-1,1).getValues();
Line 209 is defining a variable within your monitor function. This variable "status" is getting the values in a specified range. Specifically, it is getting the current form sheet range. Google apps script has 4 different ways of writing getRange(), and this case has 4 arguments like this: getRange(row, column, numRows, numColumns)
The original code as is is saying, "From my current form sheet, start from the second row and first column, go all the way to the last row, and do all of this for an entire one column (column 1)".
But what if you have some data on rows 2:5 for columns B:Z (2:26 in javascript), and you have no data on rows 6 and beyond? You're emails will be sent for rows 2:5, and you'll receive error messages for lines 6:1000 or so (whatever "last" is) in column 1(javascript) or column 0 (excel/google sheet); in other words, column A will update with hundreds of error messages and depending on your settings you may have received hundreds of blank emails!
Update Line 209 precisely at the last argument of getRange(), where you specify how many columns you want to collect data. Choose up to the column where you know there will always be data, such as a Timestamp column if you're using google forms: var status = c.fs.getRange(2,1,last-1,1).getValues();
You've just set up a reference column(s) to check whether there is data to be emailed! Now, the next code is your for loop which checks status line by line, or row by row. In the code at Line 211 you are setting the condition when to run your email function called "doIt".
As is, Line 211 if( status[i][0] === '' ) says "If status, at the first column, is equal to blank... then run function doIt". But column A is not the column where my data lives! Column A is where my email statuses and error messages live. This condition is only preventing resending emails that have already been sent, or from sending emails where there has been an error.
Here is what your if statement should look like at Line 211:
if( status[i][0] === '' && status[i][YOUR REFERENCE COLUMN] !== '' )
doIt_(i+2);
if( status[i][0] === '' && status[i][YOUR REFERENCE COLUMN] === '' )
return;
This statement is saying, "If status at my first column is blank AND my reference column is not blank, then run my email function doIt...If status at my first column is blank AND my reference column is blank, then stop the for loop."
Save your code. You have just updated your code to accept automatic triggers! Set your time driven trigger and give it a test run!
Google had an app engine failure sometime on Friday, October 26 around 9:30am CDT. The last time I had a scripted email send with the name variable successfully changed was between 11:33pm Oct. 25, 2012 and 12:16pm Oct. 26...
I think these events may be related somehow - either way, they are all on Google's end...