FormEmailer is sending emails from my address instead of FormEmailer - google-apps-script

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...

Related

Google script editor send email on value insert or change

I would like to make my sheets to send email message once one field is updated/inserted.
Was trying to follow a few guides, but unfortunately, not getting the result I want
Lets say I have this document:
The most important column is "I" - if the value is inserted here (date) - email must be sent to the client. Client's email can be found in "E" column.
So, what I have to do is to take email from "E" and send him the email with correct date from "I" field.
In this scenario: I have to send the email to user "a#a.com" with the date "2020-01-16"
These rows can be inserted any time since it's connected with Google forms, so the script should always look up if there are any new rows.
You have to use an installable trigger, it might be on form submit or on change
The first will be run every time a new form submission is done. The second will be triggered every time a change (edit, insert row, remove row, etc) is done. Please bear in mind that each trigger has its own event object.
Reference
https://developers.google.com/apps-script/guides/triggers/installable

The coordinates of the range are outside the dimensions of the sheet (google-script)

I have a really very odd problem, which seems to have to do with the sequence i execute scripts. After investigating for hours, I cant explain it at all.
I have a google sheets script which gets emails from an email account and parses them according to given rules into a speadsheets.
I have many of those methods, all leveraging common classes like getEmails, etc.
Every single method of parsing works well and delivers the respected result. But when I run them in a big method one after the other it reports the error
"The coordinates of the range are outside the dimensions of the sheet."
after executing some of the methods correctly. The error occurs in the following line:
var resultArray = sheet.getRange(startrow, column, sheet.getLastRow(), 1).getValues();
and is based on the call
sheet.getLastRow()
(I can not even call this in the logger, it works for lets say 5 out of the 10 methods and then all the sudden i get the error)
Every of those methods parse a different email with a different pattern but does this only for new emails. Therefore I have to get the hashs of the old emails (thats the call) from the google sheets column 1 to work only on new email hashes. This process breaks somehow.
What is striking me is that i can execute any of the methods isolated without an error.
Any ideas?
As mentioned I have tried isolated and i have tried to change order or to run only 2 of the methods.. with the same result. I assume some variable is not set back properly... but i have no idea how that can lead to this error.
By the way: the code was working for the past few weeks without error (also for the combined method). The errors have started like a week ago without any code changes.
I came across the same issue.
This is a sample of the code that was causing the bug for me:
var priceSheet = ss.getSheetByName(priceSheetName);
var rangeToSort = priceSheet.getRange(2,1,priceSheet.getLastRow(),priceSheet.getLastColumn());
rangeToSort.sort(1);
ss.getSheetByName("my sheet").getRange(startingRow,pasteColumn,pasteHoldings.length,1).setValues(pasteHoldings);
The error The coordinates of the range are outside the dimensions of the sheet was raised on line 4 (similar to your scenario), but the issue was occurring when I was trying to sort a range that extended beyond the last row of the sheet i.e.
last row with contents = last row of the sheet
Sort row start range = 2
Number of rows = priceSheet.getLastRow() <-- this is impossible because the sort row start range is great than 1
The fix for me was to adjust the sort range down by the start row - 1
var priceSheet = ss.getSheetByName(priceSheetName);
var rangeToSort = priceSheet.getRange(2,1,priceSheet.getLastRow()-1,priceSheet.getLastColumn());
rangeToSort.sort(1);
ss.getSheetByName("my sheet").getRange(startingRow,pasteColumn,pasteHoldings.length,1).setValues(pasteHoldings);
This appears to be a bug in Google Sheets script: either the sort functionality, or at the very least the error handling is raising the error with reference to the wrong row.
My recommendation would be to check your use of .getLastRow() and see if it corresponds to a starting row greater than 1. Then adjust the .getLastRow() by starting row - 1
Would you happen to have your sort range starting on something other than row 1?
I was testing this out and I have my data to sort on A7:N100.
What I found was that the max row that I can have is the last row in the range minus the header rows that are not in the range. For example, I have the first 6 rows that aren't in the range. I have my last row in row 100. So my range is only working with A7:N94.
To solve, I ended up adding 6 blank rows to the bottom of my page and set sort range to what I wanted (A7:N100) and this worked.

How to change background color of a cell if it is edited after a specific duration?

I have a google spreadsheet which we use to feed inventory purchase and issue data. The only problem is my staff can manipulate purchased quantity, prices and other variables at a later date. I want that if they enter the data in a cell and try to edit it whenever after 12 hours of entering the data, the cell should get highlighted. If possible, the cell should not highlight if I edit the data.
A simple solution is to have a column when this data is entered (if the data is added with a google form, then you are already set to go on that front). At that point all you need is a onEdit triggered function that fetches that timestamp, does var curTime = new Date() and then check what is the difference between them, and if it's greater than 12 hours you do a e.range.setBackground('red') or whatever color you wish (remember that the function must have e defined like function checker(e)).
Having it ignore edits done by you is also simple, just have an a simple
var editUser = Session.getEffectiveUser().getEmail()
if (editUser == 'myEmail#gmail.com`)
return 1;
and it will stop the script if the session users email matches your own.
For future reference please also provide what code you have so far, as currently we don't know what research you have done so far, what worked and what did not. Remember — here you won't get someone to write the program for you, only solve issues you have with code you already have.

Keeping value after reference cell has been changed

I need cell B3 to reference B1 while blank.
Once you put something in B1 it'll keep that value forever, even once B1 get's changed to something else.
This is my situation:
Basically I have a sheet that is fed by a Google form and each submission needs three key reference numbers each kept in columns a,b,c
A = Unit Number/Individuals name (There may be duplicates down the sheet as this is per submission)
B = Work Order (Imputed by me after actual work on unit has been done)
C = Cry Number/Reference number (Automatically generated per submission; no duplicates)
I then have a frozen row at the top which contains a search bar that you can search for the cry number (A1)(Which has a Data Validation set to column C so that you can only search valid cry numbers) and then a cell to add a W/O to that Cry Number (B1)
In column B3:1000, I have this formula copied down:
B3=if(isblank($C3),"",if($A$1=$C3, SUBSTITUTE($B$1,"",$B$1),""))
...which makes it so that if you select say "CN-168" (A valid cry number) and in 'B1' type "W1134" that work order number will be assigned.
Now I need that work order to stay there regardless of when 'A1' changes so that you can do the process over again on another submission.
Is it possible to do with formulas? If not, then a Google Script?
Here is a template of what I'm dealing with but not to the same scale as my Data Base
Its not possible with formulas but easily done with apps script. look at the onEdit trigger and the documentation for SpreadsheetApp to setValues to the appropiate ranges.
If you want to be 100% complete you also need a time trigger (say every 10 minutes) to check that a row wasnt missed. It can be missed during apps script errors/outages or when the sheet is changed from outside the sheets webpage/app (For example using the http spreadsheet api)

ABOUT: Tutorial: Sending emails from a Spreadsheet

Is it possible to get this script updated? In 2009 it may have worked, but it doesn't now.
Tutorial: Sending emails from a Spreadsheet -
Quick link to Google Developers Tutorial
I can't for the life of me get my own script to work. Having a problem incrementing the rows correctly when it checks before sending, which is either leaving me sending a dozen e-mails of a single row of data or if I try to implement a while loop, I've ended up sending myself over hundreds of e-mails and google then stops me from using the function any further until the next day.
My specific script question is HERE, except I don't think I worded it correctly because no one is replying.
It seems that you forgot a couple of things in your script :
1° : var dataRange = sheet.getRange(sRow,1,1,cols); // this gets only 1 row in your sheet so it is normal that the loop doesn't work (length=1).
I'd suggest to replace the height value by the last row value (see docs to get that value) to make the loop iterate through every rows.
2° when you use .setValue(EMAIL_SENT); the value of EMAIL_SENT is not defined in your code (it is defined outside the function in the tutorial).
I'd suggest to add a statement like this : var EMAIL_SENT="EMAIL_SENT" or, more simply use the string value in your 'setValue' statement like this : .setValue("EMAIL_SENT");