3

I've made my first little test web app and have that "technology" working, as per: enter image description here

The next step is to enable a customer to be able to click on a status URL in an email so they can view the scheduling status of their job. So, the question:

Is it possible to create a URL which the webapp can then parse and pull data for?

A URL something like: https://script.google.com/a/macros/example.com/s/AKfycbwMgBLtVP8Ur8GKNpGxxjna_zr5BlegmvlFqXQW1g6q5UfksAg/exec/+123+sample+street+samplesuburb

and then the web app would pull and display the scheduling info related to that address.

Many thanks ~

2
  • Add code as text instead as image. Think on screen readers, copy the code to an answer, etc. Commented Jun 13, 2017 at 12:21
  • Good point, thanks. Commented Jun 13, 2017 at 19:03

2 Answers 2

11

You can inspect the 'e' object of the doGet() function to get URL parameters

 // yourUrl/?a=1&b=2&c=3&c=4

function doGet(e){

 e.queryString // will be a=1&b=2&c=3&c=4
 e.parameter; // will be {"a": "1", "b": "2", "c": "3"}. For parameters that have multiple values, this only returns the first value
 e.parameters; // will be {"a": ["1"], "b": ["2"], "c": ["3", "4"]}. Returns array of values for each key.



}

See 'URL parameters' section here https://developers.google.com/apps-script/guides/web

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

4 Comments

I got it working and have a virtual smile from ear to ear. Thank you Anton, this is just GREAT.
Glad I could help!
i don't get it. What's e and how do we set a value into e?
You don't set any values into e. E is an event object passed to the doGet function as soon as doGet receives an incoming HTTP request. You can then inspect the event object and extract the details you need. Please refer to Apps Script Docs
4

As a working test, I used:

A web app URL with a parameter, like: https://script.google.com/a/macros/example.com/s/AKfycbwMgBLhu88Ur8GKNpGxxjna_zr5BlegmvlFqXQW1g6q5UPksAg/exec?street=65_Fields_Ave ...with "street=65_Fields_Ave" concatenated to the web app URL from spreadsheet data for a specific customer, to be included in their Booking email.

And read the street like (the real script will test for suburb too):

function doGet(e) {
  var paramStreet = e.parameter.street;          // format like "123_Sample_Street"
  var street = paramStreet.replace(/#|_/g,' ');  // format like "123 Sample Street"

Then searched for the row in the spreadsheet and presented the data via:

var html = HtmlService.createTemplateFromFile('index');
html.name = fullName;
html.street = street;
html.status = schedStatus;

return html.evaluate();

And in the HTML file:

<div> 
  <h1>Scheduling Status</h1>
  <p>Primary Contact: <?= name; ?></p>
  <p>Street: <?= street; ?></p>
  <p>Status: <?= status; ?>
</div>

Note that the web app needs to be published as a new version after each change: enter image description here

Works like a charm! Thank you Anton Dementiev.

Comments

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.