This is related to a question I have posted previously.
I have a batch of CSV files that contain a data set obtained from an issue tracker tool. These I've uploaded to google drive and are presented as charts and lists from a google site.
This works reasonable well as all I now have to do is update the files in google drive and the site is automatically updated.
The displayed charts work well, but I want to present the lists as an HTML table (as opposed to an embedded sheet).
An app script seems the most logical way to do this. However, in order to do this, I need to provide the URL of the sheet containing the data to the app script. This is proving to be more difficult than I anticipated.
I attempted passing the data source as a parameter by directly linking the app script URL (xxxxxx/exec?source=yyyy), but the app script gadget in google sites doesn't pass through parameters.
I attempted to embed the script URL (with parameters) within an iframe - as suggested elsewhere, but without any luck.
Has anyone got any suggestions? Thanks.
Google Apps Script gadget can't include parameters in the gadget settings, instead, add the parameters to the links to the Google Site page
https://sites.google.com/sites/mysite/mypage?par1=A&par2=B
Regarding having several instance of the same Google Apps Script gadget that could be a problem. I think that the better way to proceed is to make copies of your script and make a different set of parameters for each one.
Step by step
Create a site
Create a script
Add the gs code
In this case the code create a template from a file that has a printlet that shows the Hellow World! if the URL parameter message is equal to true, otherwise it you show undefined.
function doGet(e) {
var template = HtmlService.createTemplateFromFile('Index');
if(e.parameter.message === 'true') template.message = 'Hello World!';
var output = template.evaluate();
return output;
}
Create a HTML file and add the HTML code
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<p><strong>Message:</strong> <?!=message?></p>
</body>
</html>
Publish your web app
Create a page
Insert a Google Apps Script gadget
Save the page
Write the page URL and the required parameters in the browser address box or in a link
https://sites.google.com/a/rubenrivera.mx/ejemplos/posts/1?message=true
For apps script web apps embedded in classic google site,querystring parameters work well. Instead do not work if embedded in new google site,and this is a big problem, means that classic web sites that uses querystring cannot be migrated, and soon classic google site will stop working.
Related
I have created a Google Sheet to process a Sales and send mail from it. But I have found a limitation, it works only on PC and cannot be used on an android phone using the Sheets app. Is there a way to convert my code to a web app, use Sheets as my database and use the interface from my phone?
Create a deployment of the project as a web-app. you'll probably want to use the Test Deployment for developing and you will need the doGet(e) function to get the page up and running.
function doGet(e)
{
var html = HtmlService.createHtmlOutputFromFile("your_HTML_file_here");
return html;
}
The function above creates the webpage but the rest of the code will end up in the html file that contains the web page.
To interact with google and its services you can use
google.script.run
This allows the user to run google script code from an html page.
Not sure what you mean by "convert". You can publish your project as web app (for that you need doGet() function and some kind of UI) and then access it on mobile via URL.
I have a single Google Script that I have developed, yet it is a single script that should be placed on several Google Sites pages, I would like to be able to know using the script which website has loaded my script.
How can the script identify which page has loaded it?
On a web app inserted as gadget on Google Sites, to get the name of the site we could use getActiveSite() to get the Site object representing the active site and then getName(), something like the following:
var mySite = SiteApp.getActiveSite();
var mySiteName = mySite.getName();
I have code that uses the script to enter data in a spreadsheet and I want it to redirect page after execution to website how to do that. I tried responding. sendredirect and it isn't working I guess. I tried searching everywhere didn't got anything to work. All I need is how to redirect from google script to a certain page. I am using an HTML form of calling google script.
Using a Google Site with an embedded Google Apps Script, I'm displaying some data from a database using JDBC. The Google Apps Script uses doGet to load an HTML page:
function doGet() {
return HtmlService.createHtmlOutputFromFile('index');
}
...the index.html page in turn calls a function in my Apps Script to get some database data:
google.script.run.withSuccessHandler(mySuccessHandler).getSomeDBData();
When the mySuccesshandler is called, I render the data with the JQuery.
This works. However, embedded Google Apps Scripts have a statically defined height. A post on SO suggested developing a custom Google Gadget which dynamically resizes when content changes.
But I can't find any examples, or confirmation that I can port my current Google Apps Script to my own Gadget. The documentation on working with remote content doesn't mention databases.
I tried placing the call to my App Script in the Gadget XML file:
google.script.run.withSuccessHandler(mySuccessHandler).getSomeDBData();
However, this failed with cannot call run of undefined. So is there any way I can call a GAS from a custom Google Widget?
You cant mix them like that, they are different and disconnected (for example how would the xml gadget know which apps script to call in your attempt?).
The easiest would be to use the apps script solely as a data provider like json from a contentService in doGet. From the xml gadget you do an ajax get to the apps script published url & any needed parameters.
To avoid auth hassles publish script to run as you with anonymous access.
I want to embed Google Drive Scripts/ project from Google Sites but I can not.
Google Sites alert me with a message
This url is not recognised as a valid Apps Script
after I
created project-script from Google Drive,
added a function function doget(e) { code; code; code; ... },
published the script ("Deploy as web app"),
retrieved the link link (e.g: https://script.google.com…1DkWAQ/exec), and
in the Google Sites page,
I edited page and inserted a script from menu: Insert > Apps Script Gadget.
In the next page I enter script's link but a message box shows up: "This url is not recognised as a valid Apps Script"
Where I am wrong?
My question is: Can I execute Google Drive Script without adding code in site's page? Is it possible to execute from several Google Sites' pages a Google Drive Script with different parameters?
Thanks,
Michele
The url is different when embedded in a Google site, here is an example that can be inserted :
`https://sites.google.com/macros/exec?service=keyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
You can pick the key in the standalone url.
I must admit that the interface is not really clear about that, nor is the documentation
EDIT : since some people seems to be sceptic ;-) here is an example with a shared script written as a script file :
the url given for a standalone app is :
https://script.google.com/macros/s/AKfycbxlPTVLSLfO3d1w2vSrMzzh57p9DJM6ivCIHiIfTB2AKqubSs1L/exec
The same script in the site page is :
https://sites.google.com/macros/exec?service=AKfycbxlPTVLSLfO3d1w2vSrMzzh57p9DJM6ivCIHiIfTB2AKqubSs1L
feel free to check ;-)
in the gadget properties it shows up like this :
I believe this summarizes the correct format for URLs of scripts saved on Drive for inserting with a Script Gadget on Google Sites:
Regular Google user:
https://sites.google.com/macros/exec?service=KEY
Google Apps domain:
https://sites.google.com/a/macros/MYDOMAIN/exec?service=KEY
Note the domain part is 'sites.google.com' not 'script.google.com'
As my experiences, you can't create an Apps script in Google Drive and then embed it in Sites.
To do that, log into your site's dashboard. You can do that by selecting menu item More > Manage site from your site (with logged in account). Then select tab Apps Scripts, hit the button Add new script. From there you can code your script. When you're done, come back to your site, edit a page and insert that script into your page.