Reputation: 300
I have built a rather useful tool for my work place that allows me to keep track of employee attendance. My latest addition is, when an infraction is flagged an email goes out with a link to that infractions ID. I want to be able to click that link, load the html page and pass the infraction ID to the page. I have been doing a lot of searching, but can't seem to find a clear answer, nor a case that closely resembles mine. The accepted answers I have found don't seem to apply to my situation.
Here is the example:
URL: https://script.google.com/a/macros/mycomp.com/s/blahblahmyID/dev
HREF: https://script.google.com/a/macros/mycomp.com/s/blahblahmyID/dev?cID=1457989239035-cc3050b8
I want to pass the 1457989239035-cc3050b8
value to my page. Once I get that on the page I can handle it from there, just can't find a way to pull it from a HREF link in an email. One of the drawbacks of not using a traditional website.
Here is my doGet()
code to load the Index.html
from the app:
function doGet(e) {
return HtmlService
.createTemplateFromFile('Index')
.evaluate()
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
Not sure how useful that code is though as it is pretty standard. Am I pretty out of luck trying to do this?
UPDATE:
I realized that I haven't given enough information on how this system works. I am using HTML to serve information stored on spreadsheets (google sheets). The ID in question is a reference to an entry in the spreadsheet (column 1). It isn't a part of the app, I am just looking to pass the value of the row
I need to get data from. If I have this value I can run a script to get all the other values from the spreadsheet.
Upvotes: 1
Views: 671
Reputation: 46794
The ID is an attribute of the e.parameter object, you should get it using something like id=e.parameter.id
You can pass it just as you show it in your question , right after the question mark in the url
HREF:https://script.google.com/a/macros/mycomp.com/s/blahblahmyID/exec?id=1457989239035-cc3050b8
The server code will get the value, store it somewhere and be ready to send it back when the client javaScript asks for it.
See shematic example below:
function doGet(e) {
var id = e.parameter.id
PropertiesService.getScriptProperties().setProperty('id',id);
return HtmlService
.createTemplateFromFile('Index')
.evaluate()
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
function returnID(){
return PropertiesService.getScriptProperties().getProperty('id');
}
// in your client javascript, add a call like this (outside of any function so it is executed on page load... or use onload="theFunctionName"...):
google.script.run.withSuccessHandler(getID).returnID();
function getID(id){
console.log(id);
}
Upvotes: 1