'I need to accurately find the form response id using google scripts
I have a simple form and I want to forward the response pages to my email address so I can click through straight to the result of that form submission. Using the code below it gives me a form response ID but it doesn't match the actual response ID in the URL when I navigate there on google forms. The form ID works
function onSubmit(e) {
//get entry id
var entryId = e.response.getId();
//get form ID
var formId = e.source.getId();
var soloResponse = "https://docs.google.com/forms/d/" + formId + "/edit#response=" + entryId
//build email from form data
var email = "test";
var subject = "test";
var body = soloResponse;
//send email
GmailApp.sendEmail(email, subject, body);
}
Solution 1:[1]
you don't have to create your own url to go to the entered response
the class FormResponse has a function getEditResponseUrl()
which returns the full edit url of that response
function onSubmit(e) {
//build email from form data
var email = "test";
var subject = "test";
var body = e.response.getEditResponseUrl();
//send email
GmailApp.sendEmail(email, subject, body);
}
but if you want, you can still manually create your edit link like this:
function onSubmit(e) {
//get entry id
var entryId = e.response.getId();
//get form ID
var formId = e.source.getId();
var soloResponse = "https://docs.google.com/forms/d/" + formId + "/viewform?edit2=" + entryId;
//build email from form data
var email = "test";
var subject = "test";
var body = soloResponse;
//send email
GmailApp.sendEmail(email, subject, body);
}
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 |