The id of a FormResponse when a response is submitted is different when you list all FormResponses

好久不见. 提交于 2019-11-29 11:53:12

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());
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!