'Retrieving the link to a response from a Google Form

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



Solution 1:[1]

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()  
}

Solution 2:[2]

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();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Amit Agarwal
Solution 2 Earleking