I want to include a variable that I normally use in a .gs file in my html file. For example, the following code would make variable 'value' be the content of whatever is in cell A1:
var value = SpreadsheetApp.getActiveSheet().getRange("A1").getValue();
How can I include this variable in my .html file, so that typing 'value' in the html file will return the contents of cell A1?
EDIT
What I'm trying to achieve is build a mail action button that automatically submits a google form, filled with the data in the spreadsheet. The script I have for the .html file is as follows:
<div>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"action": {
"@type": "ConfirmAction",
"name": "Accept",
"handler": {
"@type": "HttpActionHandler",
"url": "https://docs.google.com/forms/d/139j-0POMG9BVqttXnY8l-6YMI7M2DReREIuJJd_waJE/formResponse?ifq&entry.1766440389=" + value + "&entry.1329637906&submit=Submit"
}
},
"description": ""
}
</script>
</div>
The button works perfectly fine, but I need to prefill the form by adding the variable in the middle of the url (under 'handler' where I typed " + value + "), containing the contents of the cell. Only problem is that I can't figure out how to integrate that variable in the .html file
You have a text formula:
"url": "https://docs.google.com/forms/d/139j-0POMG9BVqttXnY8l-6YMI7M2DReREIuJJd_waJE/formResponse?ifq&entry.1766440389=" + value + "&entry.1329637906&submit=Submit"
And you are adding a variable to a URL search string. You want the value to be looked up from the spreadsheet, and put into the URL.
So, I guess you have a button that starts the process? When the button is clicked, it should run google.script.run
. Then, when the server side .gs
function is done running, it will return a value, and you will need an withSuccessHandler(function)
to start the function that will take the returned value, and put it into the URL.
Start with reading the documentation for google.script.run
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.