17

So I've got a Google Form where I'd like to pass in a parameter from an email link like this:

https://docs.google.com/URL/forms/d/LONGSTRING/viewform?id=12345

I'd like to be able to grab that id and pass it into the spreadsheet recording results. Now I've got writing to a spreadsheet down, but getting the id is problematic.

I've already tried:

function doGet(e) {
  var id = e.parameter.id;
  Logger.log(id);
}

and

function doPost(e) {
 var id = e.parameter.id;
 Logger.log("do post " + id);
}

Both of which throw errors when I view the execution transcript, which I suspect is because they're designed to run within deployed webapps.

Additionally, I've tried using plain old javascript to do something like:

var formUrl = window.location.href;
var formId = formUrl.split('?id=')[1];

which also throws errors when you view the execution transcript .

Any other ideas?? Maybe I can get the information in another way?

3
  • 1
    But if the parameter is on the Google Form URL, how do you expect it go to your script? If the parameter were on your script URL your first attempts would work. Can you explain more the overview of what you're attempting? Commented Feb 5, 2014 at 10:31
  • This script is attached to the Form. I was hoping to put this URL into automated emails and pass in information that's stored in the email. In this case there are tracking IDs associated with the emails (they are tickets) and I'd like to pass that information into the spreadsheet. So, I know that I can format the automated emails to pass in the id into the URL that a user would click to go to the form. Commented Feb 24, 2014 at 17:16
  • This question partially duplicates this one and both are also being discussed on the StackExchange site for Web Applications. Commented Jul 6, 2015 at 20:01

2 Answers 2

19

I think you can't use your own id, you have to use the id of the Google Form's "Item" object. You can figure out the id by viewing a prefilled form. In the Form edit screen, click "Responses", "Get Pre-filled URL". Fill in the field that you want to use and click Submit. On the new page, you are given a URL in "Share this link to pre-fill the responses" . Examine that url and you can see "get" arguments like ?entry.265525444=mytext . Replace mytext with whatever you want to be in the field.

The complete URL will be something similar to this:

https://docs.google.com/forms/d/e/1FA...SkQ/viewform?usp=pp_url&entry.265525444=mytext

This will display the field on your form, however. I myself was searching for how to make such a field readonly or invisible when I got here, but I hope this shows you a new direction to try.

Sign up to request clarification or add additional context in comments.

4 Comments

I'm looking for the same thing as you. Did you find a solution by any chance, or do you know whether anyone's submitted a feature request for this that I can vote up?
@Daniel: No, I never figured out how to pass in a hidden field, sorry. I moved on to other things.
You can also find the entry.XXXXXXXXX info by inspecting the source in the preview form page.
@Daniel's comment is insteresting since the URL it automatically generates now is like obfuscated. But still, if you manually create this `?entry.111111=xxxxxx' it works. Find the entry, and add the query to the non-shortened URL and it works!
-4

I am assuming you are trying to get the form id?

You will need to set up a trigger that will run on form submit.

function onSubmit(){

  var form = FormApp.getActiveForm();
  var formID = form.getId();

}

1 Comment

No, I was trying to get some URL parameters, which in the example was 'id'. For example: "www.google.com?id=1234&name=JohnDoe"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.