I have a Google Form which outputs responses to a Google Sheet. Some of my form questions have long paragraph responses, so I'd like to be able to click a link on each row from my tracking sheet and have it open the original response page as seen from the Form's "responses" tab.
The URL I'm trying to generate, which I get by going to Responses -> Individual from my Form, looks like:
https://docs.google.com/forms/d/<form_id>/edit#response=<response_id>
I have looked at the FormResponse
API documentation, but I can't manage to extract the same ID used by the Google Form viewer from a FormResponse
object. While I know the appropriate form ID, the response ID that is valid for that URL isn't the same one returned by either FormResponse.getId()
or as part of FormResponse.getEditResponseUrl()
. In other words, I can't get the data from the Forms API that's needed to generate that link. I'd rather not use edit links, which they do support generating, to view my responses.
My end goal is to have a link with the format shown above, in each row of my response form. A correct link with that format brings you to the individual response viewer page for the particular response in that row. i.e., I'd like to turn this:
+-----------+------------+
|Question 1 | Question 2 |
+-----------+------------+
|Long answer| Another ans|
+-----------+------------+
|One more an| Additional |
+-----------+------------+
Into this
+-----------+------------+------------------------------------------------------------+
|Question 1 | Question 2 | View link |
+-----------+------------+------------------------------------------------------------+
|Long answer| Another ans| https://docs.google.com/forms/d/abc123/edit#response=def456|
+-----------+------------+------------------------------------------------------------+
|One more an| Additional | https://docs.google.com/forms/d/abc123/edit#response=ghi789|
+-----------+------------+------------------------------------------------------------+
For reference, I tried generating the URL as "https://docs.google.com/forms/d/" + formId + "/edit#response=" + responses[i].getId()
, but when visiting that URL it says the response ID is invalid.
Is there a way, either via an Apps Script or other configuration, to produce a link back to each individual response in my output sheet?
You want to achieve to create the Spreadsheet which has the following value using Google Apps Script.
+-----------+------------+------------------------------------------------------------+
|Question 1 | Question 2 | View link |
+-----------+------------+------------------------------------------------------------+
|Long answer| Another ans| https://docs.google.com/forms/d/abc123/edit#response=def456|
+-----------+------------+------------------------------------------------------------+
|One more an| Additional | https://docs.google.com/forms/d/abc123/edit#response=ghi789|
+-----------+------------+------------------------------------------------------------+
You want to see the response page with the read only.
If my understanding is correct, how about the following workaround?
toPrefilledUrl()
can submit. So it is not read only page.Unfortunately, from above situations, it is required to think of the workaround. In this workaround, I used toPrefilledUrl()
and Web Apps. The flow of this workaround is as follows.
toPrefilledUrl()
is used as the query parameter.toPrefilledUrl()
, and the submit button is removed. Then, the edited HTML is opened.By this, the read-only response can be displayed.
In order to use this workaround, please do the following flow.
Please open the script editor of the Google Form you want to use. And copy and paste the following script to the script editor.
function doGet(e) {
var url = Utilities.newBlob(Utilities.base64Decode(e.parameter.u)).getDataAsString();
var html = UrlFetchApp.fetch(url)
.getBlob()
.getDataAsString()
.replace('<span class="quantumWizButtonPaperbuttonLabel exportLabel">Submit</span>', "");
return HtmlService.createHtmlOutput(html);
}
function myFunction() {
var webApps = ScriptApp.getService().getUrl();
var form = FormApp.getActiveForm();
var items = form.getItems();
var headers = form.getItems().map(function(e) {return e.getTitle()});
headers.push("View link");
var formId = form.getId();
var responses = form.getResponses();
var obj = responses.map(function(e, i) {
var temp = e.getItemResponses().reduce(function(o, f) {
o[f.getItem().getTitle()] = f.getResponse();
return o;
}, {})
temp["View link"] = "=HYPERLINK(\"" + webApps + "?u=" + Utilities.base64Encode(e.toPrefilledUrl()) + "\", \"response" + (i + 1) + "\")";
return temp;
});
var values = obj.map(function(e) {
return headers.map(function(f) {
return f in e ? (typeof e[f] == "object" ? e[f].join(",") : e[f]) : "";
})
});
values.unshift(headers);
// As a sample, it creates new Spreadsheet and put values.
var sheet = SpreadsheetApp.create("sampleSpreadsheet").getSheets()[0];
sheet.getRange(1, 1, values.length, values[0].length).setValues(values);
}
Only myself
is used, only you can access to Web Apps. At that time, please use your access token.myFunction()
. By this, new Spreadsheet is created.By this, Web Apps is run and you can see the response page with the read only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With