Each user is allowed to send data through a form multiple times, but they are allowed to send data once every 3 hours. Additionally, I had to calculate a new value from timestamp of each response.
Between writing my own web page with PHP script and using a service which allow me to create forms, I decided to use the further, actually Google Forms with Google App Scripts (the responsive graphical design was the main reason).
My script is in the response sheet and is triggered on submit.
I cannot prevent users from sending more than one response within 3 hours, because function triggered on submit is run after the data are already submitted and written into the spreadsheet.
The second idea was to mark first answer as good and the subsequent in the following 3 hours as bad (it has some other positive consequences) and the technique used is private cache (getUserCache). Marking works (on the second worksheet, where the data are copied after submitting), but every user in the following 3 hours get mark bad.
Now I know that the problem is that triggered functions are run under my account, but now I have no idea how to put restrictions in my form.
Is it possible to to distinguish the first response from other responses in a 3 hours time span in Google Forms or should I start to write my own web page and script which will create client-side cookies with expiration time equal 3 hours?
EDIT: I am using a G-Suite account and I am not collecting email addresses. I can use my private account, too - if necessary.
Maybe I will collect photos with the same form, so the log in will be neccessary. But, in the first moment I am working without question od type file upload.
And this is my code which works with cache (120 ms is only for testing, there should be 3 hours):
var cache = CacheService.getUserCache();
var value = cache.get('answered');
if (value === null) {
cache.put('answered', 'yes',120);
var comment = 'first answer';
}
else {
var comment = 'another answer';
}
... and after that:
var cellComment = destinationSheet.getRange(destinationSheet.getLastRow(),columnCount+2,1,1);
cellComment.setValue(comment);
It works, but I get comment 'another answer' for all users in the first two minutes.