I have a script attached to a Google Form which sends a notification to a Discord channel on submission. I want to include a direct link to the individual response (link looks like https://docs.google.com/forms/d/<myformid>/edit#response=<responseid>
). How can I retrieve that link? I get part of the link up to /edit
with Form.getEditUrl()
but I can't get the correct id. I checked FormResponse.getId()
but that doesn't link me to any response.
Since you know the response Id, you can use the geEditResponseUrl method to get the direct link to the form response. Do note that anyone with this URL can edit the response.
function getEditUrl(responseId) {
var form = FormApp.getActiveForm();
var response = form.getResponse(responseId);
return response.getEditResponseUrl()
}
You can get the responseId through the .getId() method.
let response = form.getResponse(responseId);
let responseId = response.getId();
Or if you are doing this onSubmit,
let form = FormApp.getActiveForm();
let allResponses = form.getResponses();
let latestResponse = allResponses[allResponses.length - 1];
let responseId = latestResponse.getId();
What you want is the url to the Editor of the Form opened to the correct tab
var responseId = e.response.getId()
var urlString = "https://docs.google.com/forms/d/" + formId + "/edit#response=" + responseId
The Problem is that the getId() function returns a different type of ID then the one that is generated on the edit screen. I tried both of these examples:
function onFormSubmit(e){
var responseId = e.response.getId()
}
and from Earlking's Response
var allResponses = thisForm.getResponses();
var latestResponse = allResponses[allResponses.length - 1];
var responseId = latestResponse.getId();
They both give the same ID, But not the required URL ID,
Here is a Snippet comparing the URLs https://docs.google.com/forms/d/FORMID/edit#response=ACYDBNh8k40Y7zxtUeYzw8wDwRx4pggu8APuxl5TmInVVieXN-SrmTW8tK0zHvQPmVsnYzY
https://docs.google.com/forms/d/FORMID/edit#response=2_ABaOnuet7P69_wc3S4QJkgkjS4abty4aDD9Zn1IQ8bhSKyGiynGGtuyg1v0A-xkLgOMelUE
After the edit#response= they are different. The first one I copied from my Form editor opened to the last response. The second is generated by the code. It will take you to your form edit page, but redirects to open on the first response when the url has an error.
Seems like a Bug or an Undeveloped Feature.
© 2022 - 2024 — McMap. All rights reserved.