Retrieving the link to a response from a Google Form
Asked Answered
F

3

10

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.

Here's how to get to that link manually via edit form: enter image description here

Francinafrancine answered 21/1, 2018 at 16:11 Comment(0)
S
0

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()  
}
Sanatory answered 22/1, 2018 at 8:28 Comment(4)
I don't want to edit the response. I'm looking for a link to it with read-only access. I've added a screenshot to the OP about how to get there by hand via edit form.Francinafrancine
@sascha_lamp, the suggested solution does not work, did you find a fix?Woll
@Woll sorry, I haven't found a fix yetFrancinafrancine
Pity that the API does not expose this.... could be very handyWoll
L
0

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();
Lem answered 24/2, 2022 at 21:39 Comment(0)
G
0

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.

Gilreath answered 15/10, 2022 at 23:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.