0

I am trying to pass a query param within the url of google form and submit that form to other people to fill it, so I would like onSubmit event to check for that query param and get it.

I have the following code on my onSubmit Event as below:

function onFormSubmit(e){
  var formResponses = FormApp.getActiveForm().getResponses();
  var formResponse = formResponses[formResponses.length-1];
  var itemResponses = formResponse.getItemResponses();

  for (var j = 0; j < itemResponses.length; j++) {
    var itemResponse = itemResponses[j];
    Logger.log('Last response to the question "%s" was "%s"',
               itemResponse.getItem().getTitle(),
               itemResponse.getResponse());
  }

  var me = Session.getActiveUser().getEmail();
  GmailApp.sendEmail(me, 'Google Form Notification Submission', 'Test');

}

And when the user fills the form I am sending url as "https://docs.google.com/forms/d/e/xyxyxyxyxyxyyx/viewform?usp=sf_link?patient_id=33333" , how do I get patient_id on formSubmit?

pranvera hoti
  • 107
  • 3
  • 15
  • I am able to get the url by Logger.log(e.response.getEditResponseUrl()); but the query param I added is not showing. – pranvera hoti Apr 08 '17 at 10:04
  • I see that your code is looping through all the itemResponses. If you need the answer to a particular question, then you will need to match the Title or item ID to the question that you want. You'll need to "hard code" the question ID or store it in Properties Service. `var title = itemResponse.getItem().getTitle(); if (title === 'Patient ID') (var patientID = itemResponse.getResponse();` Then you'll need to use JavaScript string methods to build the edit URL. Is that what you want? – Alan Wells Apr 08 '17 at 14:10
  • 1
    I believe you are trying to combine web app query param and google form. Which is not possible, if you want to build a form based on the query parameter you can do [something like this](http://stackoverflow.com/questions/42406877/google-forms-get-url-link-to-a-section-only/42410817#42410817) – Jack Brown Apr 08 '17 at 14:30

1 Answers1

1

Google Forms only process the parameters that are used to prefill a form. To learn about how to prefill a Google Form see Send a form with prefilled answers on Send your form to people and Is it possible to 'prefill' a google form using data from a google spreadsheet?.

In a comment, Jack Brown shared a link to Get URL Link to a "SECTION" only which has an answer by him where it's included the code of a Web App to serve an HTML/JavaScript/CSS form. On a comment by Sandy Good to another OP's question, she also commented that the intended Google Form behaviour / Google Form feature is not included in Google Forms and that you could use a Google Apps Script web app as an alternative.

Community
  • 1
  • 1
Rubén
  • 34,714
  • 9
  • 70
  • 166