I\'m working in a bug tracking backed by a Google Form and I think I\'m stuck with a bug in Apps Script.
When a response is submitted, my script onFormSubmit
I'm coming up against the same issue.
While my current implementation falls back on timestamps - in the unlikely (but still possible) event that two responses are submitted within the same second, my solution would fail.
Something I've noticed is that in your above examples, where the response IDs differ, they still share the first 29 characters.
Given the length and complexity of these IDs, I'd be willing to wager that these are global across all responses submitted to all google forms, and that the odds of finding two responses that share these 29 chars at the start of their string submitted to the same form are far less likely than having two respondents submitting forms at the same second.
Thus, a workaround comparing just the first part of the IDs could be successful.
if (idStoredOnFormSubmit.substr(0,29) === idFetchedFromFormResponse.substr(0,29)) {
runThisCode();
};
substr(0,29) takes 29 characters from the beginning of a string starting at index position 0.
In case others run into this, I wanted to post how I got around this behavior.
I discovered this same behavior while trying to use my FormResponse
ID in an onFormSubmit
trigger. I wanted to map the FormResponse
ID to a value returned by another API when users were allowed to edit responses. So, in order to get passed the changing FormResponse
ID I used the FormResponse
ID from onFormSubmit
response to get the saved FormResponse
and mapped the ID of the saved FormResponse
, as seen in the code below.
if (form.canEditResponse()) {
var savedResponse = form.getResponse(response.getId());
}