Is the timestamp for a Google Form response event always the same as the timestamp in the linked spreadsheet? - google-apps-script

if I get a timestamp for a Google Form submit event, using for example:
var timestamp = event.response.getTimestamp();
a time is returned e.g.
Fri Sep 26 17:54:02 GMT+12:00 2014
and in the linked spreadsheet the timestamp
is displayed in column one.
Are both timestamps always identical (i.e. is the event timestamp passed to the spreadsheet) or can they be different and the timestamp on the spreadsheet is actually the timestamp of the write to the spreadsheet?
Background: I'm making an application where when a form is submitted an email is sent to the person who has filled in the form with a confirm link. Using a query url and a webapp on the form's linked spreadsheet I can get the parameters from the query url. I now need to have a unique id to find the entry in the spreadsheet in order to to mark it as 'confirmed'. Timestamps seem a suitable way of doing this, but better ways may exist.
Thanks in advance,
Trevor

There doesn't appear to be any documentation or confirmation on this, but from my experience, the timestamp is not the time that the sheet is written to. I believe it's the form submit time, but I can't confirm that for you.
From reading your requirements however, it sounds as though there's the potential for failure as the timestamps won't be unique, and it's possible two people will submit the form simultaneously (though depending on the popularity of the form, this may be slim).
If you need a Unique ID for each entry to just confirm it was submitted, but don't need it for anything else, have you considered logging the 'Edit response URL'? That's unique to each submission, so there's no danger in mixing up submissions.

Thanks for the suggestion. Further experimentation showed that occasionally the timestamps were different at most by a second. I suspect that the event times are for submitting the form and writing to the sheet.
I've found a more elegant solution that works well. The form has a field for last name. I've attached the onformsubmit trigger to the spreadsheet that receives the form responses. By getting the current unix time in milliseconds and concatenating it to the lastname (eg.storr1411790175312) I have a unique ID to pass to the query string that is a link in the email. Further, I write the unique ID value to the correct row in the receiving spreadsheet by using the event range method, e.range, which will always return the range that triggered the current event. As the unique ID is generated once and used in both the email and the spreadsheet it is internally consistent.
Cheers
Trevor

I figured it out.
The value of event.response.getTimestamp() is same as the timestamp in linked spreadsheet.
This is because...
It seems that spreadsheet also stores timestamp in milliseconds.
If you set custom cell format to
yyyy"/"mm"/"dd" "hh":"mm":"ss":"000
you can finally make milliseconds to appear.
If you don't explicitly display milliseconds, spreadsheet automatically round it.
Ex)

Related

Auto edit MySQL data after a given time

We have a form which is stored in draft mode. That means editing any data or deleting the entire form is possible. The beginning to end process is as follows
When a person tries to submit the form for the first time, that is stored in draft. (the isDraft column is set to 0)
The user is redirected to another page where s/he can view the Form id (a generated number), name, a few other details and Edit/Delete options.
The user can click edit button to edit anything, or even delete the form.
However this will be allowed till a given date (say 15 days from the first submission date). Once that date is passed, the form can no longer be edited or deleted. In case the form isn't deleted, the isDraft column is set to 1.
Thousands of people can submit the form . So ,it is not possible to do it manually.
Our project is done using Laravel v6.2, but I want a general idea as well .
I can use a trait or ajax on the master page, but that is too risky and also, server inaccessibility can delay the process, and some users may get an advantage.
How to do it?
If there is no concrete answer, but rather only discussion , I will remove this post
Just store the date (time component depends on how accurate you want to be when you check the 15 day interval) when the form is created as draft.
When a user wants to edit it (display the edit form) or save an edit, compare the current date (and time) with the stored creation date + 15 days. If the current date is less than the creation date + 15 days, then allow the display of the edit form or save the form, otherwise display an error message.
Not sure if I understand it correctly, but I think you like to update the updated_at timestamp automatically. You can run through the Eloquent Models by create a command and just call the save Method on them.
$model->save()

How do I lock a cell's copied value determined by a formula and prevent it from updating when the referenced cell in formula does?

the sheet I'm working on generates a request number on the very first submission a user makes of a google form based off of information the user inputted in the form and a timestamp. Now, because I need for the user to be able to edit their response later which causes the form to be re-submitted, I want the request number not to be regenerated, and to stay the same as when it was initially generated. Is there any way to prevent a cell from changing from its initial value when it contains a formula that references a cell that updates?
Here is the formula contained in the cell I don't want to update with alongside its references:
=ARRAYFORMULA(ARRAY_CONSTRAIN(if(ROW(A:A)=1, "Request ID", if(D1:D="", "",C1:C&"-"&G1:G&"-"&N1:N)), MAX(if(D1:D="",0,ROW(D1:D)))-ROW()+1,1))
The formula appends different values received from the form together to create a request number (formatted as essentially C1:C-G1:G-N1:N, timestamp-System-initials) and the arrayformula and constraint ensures the formula is copied to each row in the sheet that contains a form response so far. I want this request number to stay the same as it's initial value, even as columns C, G, and N change.
Edit: Not really sure how I can provide a search history on what I've tried so far because I've been searching for anything I can to fix this problem because it's important. I've looked into indirect referencing, absolute references, considered using PropertiesService (Google Apps Script) in order to store whether the request number has been initiated before and got stuck there, considered copying the value into another column to store it but again the autoupdating feature that accompanies linking cells of course still remains an issue. I'm stuck on what kind of function/workaround I could use to achieve this. Look forward to your thoughts. I've also tried a number of other strategies as well.
Since formulas recalculate each time the spreadsheet is recalculated using a formula is not the right way to keep the original value on the current spreadsheet version. The way to achieve this is by using a script to log those values.
There are already a lot of questions about using a script to log values from one sheet to another. Here are few examples
How to Get (& Set) cell values from one sheet to another in Google Sheets?
I want to write a script to read and log values of a specific row and copy them to a new sheet

Script to apply formulas to cell drop-down

I am making a status tracker sheet that has a column for the status of each task. Right now, Column D is has the status for each task and is set up with a drop down menu:
No action needed
Needs attention
In progress
Complete
Column E has the due date for each task.
Is there a way to write a script for the drop down menu that will change the status of cells that say "No Action Needed" to "Needs attention" once the due date is within a week of the current date?
Also, what's the best way to incorporate email notifications into the script so that any time a status changes to "Needs attention", an email is sent to the owner in Column F?
This would definitely be possible through the built-in script editor.
Overall you would want to be able to interact with the sheet that this is data is stored in. The easiest way to do this is through the SpreadsheetApp class and methods.
For the first step, you would want to set up a script that checks whether the due date is within a week of the current date. This can be done using the Javascript Date Methods which can easily be compared using regular number operations such as subtraction and addition.
The second part of the script would be possible using the built-in apps script functions of MailApp.
When you have both of these parts of the scripts down, you should tie it to a trigger to ensure that the script will trigger at either given times (time-driven triggers) or at given events (event-triggers).

IFFT Populated Google Spreadsheet Log Does not Trigger onEdit Script

I have a Google Spreadsheet that IFTTT adds a line to when particular events occur. I would like a Google script to run each time a line is added. Currently, the script has an installed onEdit trigger but it isn't triggered unless I manually edit the spreadsheet.
This thread and this thread describe similar issues but I lack the knowledge to try out their proposed solutions. The first suggests using a webapp and the second suggests using a time based trigger and checking for changes in the spreadsheet.
Any guidance would be greatly appreciated.
Further Details
Each row that comes in via IFTTT represents a purchase of a random prize. One column contains the price of the purchase, another column contains the date of the purchase, and another contains purchase details. When the total amount spent changes, the spreadsheet fetches a random number and the prize associated with the number. I want those details emailed to me when a prize is bought (more specifically, I want them emailed to IFTTT so it can SMS me the details). The email and email address are generated by formulae in spreadsheet cells. A script grabs the email and address from the spreadsheet and sends the email. Currently, the email is successfully triggered when the spreadsheet is manually edited but not via the IFTTT log entry.
Most of this project is achieved via formulae in the spreadsheet, rather than scripts, as I am much more confident using them.
The onEdit() trigger only fires on user input.
You should see if you can use onFormSubmit if IFTTT sends form-info?
My workable but untidy and unsatisfying solution is as follows.
The following functions are used to record the time and date that the Total Spent cell was updated.
function timestamp() {
var d = new Date()
return d.toLocaleTimeString();
}
function datestamp() {
return new Date()
}
SPLIT() and INT() are used to manipulate the date and timestamps into usable formats that can be compared with the current date and time. The datestamp() function always gives the date in PST so I've had to add the appropriate number of hours to convert it.
One IF() cell checks whether the date is today and another IF() cell checks whether the time has a value that is less than the time 5 minutes ago.
If the conditions are satisfied (total spent was edited today and less than 5min ago) the email cell is given the value of IFTTT's email address. If not the cell gets a space.
My sendEmails script is triggered every 5 minutes by an installable time based trigger. It will send an email to the valid address if the conditions are met and a blank email address if they are not.
One workaround could be the following:
You could make a script in this spreadsheet, and save the getLastRow() value in scriptproperties.
Compare them every minute or so via a timed trigger, and when it had increased, do your thing ;)
just change the trigger to be select event type to be "On Change". This will run the script whenever you edit it and also whenever IFTTT adds the row.

Can a Google Form be auto filled and submitted, using data from a spreadsheet?

I am trying to determine how to get a script to take data from a spreadsheet and fill out a form, then submit the form. The script would be part of the spreadsheet
FORM
My Form has 3 text fields, one date, and one choose from a list field.
User Name: "TEXT"
User's Manager: "TEXT"
Start Date: "DATE"
Location: "LIST"
Cube#: "TEXT"
SPREADSHEET
The spreadsheet has rows listing a variety of users, only some of which would need to have this form submitted.
The spreadsheet has a column relating to each of the form fields plus an additional column to indicate that the form should (or should not) be submitted for this user.
I would also need the script to datestamp the cell that indicates the form should be submitted after the form has been completed.
I've seen several posts about populating forms, but they all seem to be in the creation of the form, not the population of an existing form.
I'm exceptionally new to scripting, so any help is much appreciated. Please let me know if I need to supply additional information. Thanks!
This question was about simulating form submissions: Use App Scripts to open form and make a selection.
There are numerous examples of creating timestamps.
Here is an example of a menu function that determines the currently selected row.
By adapting from those, you should be able to write a function that gathers the data from the currently active row, checks whether submission is warranted, and if so simulates a form submission of that data, then appends a timestamp to record when the action was taken.