URL parameters stripped on Google Sites? - google-apps-script

Using Google Apps Script gadget, I can use the parameters of the URL (http://sites.google.com/.../my-page?urlparameter=value&otherurlparameter=value) added to a Google Sites webpage to generate dynamic content.
But if you try to add a link to a page of a Google Site with parameters, and then save your page, the parameters are deleted : http://sites.google.com/.../my-page?urlparameter=value&otherurlparameter=value becomes http://sites.google.com/.../my-page. Same thing when trying to publish a webpage using Apps Script Service SitesApp.Page.setHtmlContent(yourHmtl).
It doesn't happen when using external URLs.
How can we bypass this limitation ?

It's possible to include relative links to pages including parameters.
Example :
in http://sites.google.com/.../home/page-1,
a link like http://sites.google.com/.../home/page-2?urlparameters will be overwritten without parameters but ../page-2?urlparameters won't be.

Related

How do I reference a support file in Google Apps project

Is it possible to use a support file from within the apps script project as a source for iframe in another HTML.
I need to do this as a part of a Web App project in Google Apps Script.
Specifically I need it to work as a menu system which is the same across multiple pages, so that I don't have to repeat the same HTML code over and over again.
Better explained in a picture
Left side menu(buttons) stays the same across pages
There are several ways to accomplish what you are looking (" I don't have to repeat the same HTML code over and over again") but using iframe is not the best way when working with Google Apps Script web applications.
First you have to decide if you want to handle your web application as a multipage or as simple page.
In any case you might find helpful to use templated HTML / scriptlets to pass the code from Google Apps Script .html files to your main html code. If you find yourself scripts hard to start with, then you might use other methods of the HTML Service
Resources
https://developers.google.com/apps-script/guides/html/
https://developers.google.com/apps-script/guides/html/templates
https://developers.google.com/apps-script/reference/html
Related
Use project Javascript and CSS files in a Google Apps Script web app?
Recent related question (no answers at this time, but with comments)
HTML Service: Templated HTML as sidebar
Is it possible to create navigation bar on Google Apps Script?
how to connect a navigation bar (<nav>) with HTML files in google appscript?

Load Image from Google Sheets using Google Apps Script

I have some data along with images in a Google Sheet.
I am sending the data as a JSON response and I have deployed the script as a web app.
I am using the code:
SpreadsheetApp.openByID("<sheet_id>").getSheets[0].getDataRange().getValues()
I am able to load the data properly but I am not able to load the images.
For the cells with image, I get Empty String.
Can you please suggest a way to load images using the same script?
If it can provide a URL to my image saved in the sheet, then also it will solve my problem as I just wan't to display the image.
At the moment, you can obtain the image URL but under very special conditions:
The image has to be defined as an "Over cell" image (it cannot be an "In-cell image", as they are not supported by Apps Script).
The images have to be inserted by URL (not by uploading it from your local system).
The way to do it would be to:
Obtain the Sheet you want the images of.
Obtain its images using the getImages() method.
Obtain the URL of each image by using the getUrl() method.
If you are interested in the possibility of obtaining "in-cell" images more easily, I suggest you visit the feature requests in the Google's Public Issue Tracker or consider creating a brand new one.

How to generate an HTML view in App Script from a Google Sheet

I have a client that uses Google forms to take orders and wants to be able to turn the resulting Sheet into a document of Packing Slips. Being a python person I am currently taking her .tsv and making nice HTML printable docs but want to be able to make a plug-in for her so that on any Sheet of this type she can click "Make Packing Slips" and it either opens a new tab with generated HTML (I'm ok using googles templating) or maybe even convert the HTML into a PDF and save it to her drive? Either way I'd rather design the document all in HTML and CSS rather than trying to make a google doc if at all possible. Is the feasible? Any starting points? Thanks!
You need to learn about Google App Script => https://developers.google.com/apps-script/overview
Then these Links should suffice
HTML Service: Create and Serve HTML
Google Container-bound Scripts for Google App Script (Can not post link for this due to low reputation)

Apps Scripts within Google Sites

So I might be doing this entirely wrong, but I am trying to create a slideshow based on images stored in a google drive folder that can be easily added (ie by a non-technical person) to a google site.
I created a script that outputs the slideshow using the HTMLService. You can view the working site at https://script.google.com/a/macros/needham.k12.ma.us/s/AKfycbyOyqTr_sEMWRVBn0e0r4NV5083_LwzZSMYwPU-25_xd2m6ZexS/exec?width=300&height=200&folderID=0B-6QUsY0bQG5ZmI4QTl4T1ZQZmc
When I try to insert this script into a google site using the Apps Script Gadget (Screenshot 1) using the link above it appears that the parameters are either lost or ignored (Screenshot 2). When I hard code the parameters into the script, the slideshow loads correctly (Screenshot 3).
Screenshot 1
Screenshot 2
Screenshot 3
You cannot add the parameters to the URL when inserting your script in a Google Site. However, you can pass the parameters to the Site URL utself and the script will pick it up.
For example,
http://sites.google.com/example.com/example-site/example-page?folderID=1235
As for the width and the height, you can adjust them when you insert the script into a Site using controls that Google Sites provides
Same happened to me. My solution was to write a google gadget that iframed my apps script and added fhe necesary parameters.

gadget in site with custom setting fields

I'm wondering if the following is possible.
When you insert your gadget in a site page, you can config some settings such as height, border and url.
Is it possible to add custom fields to config the gadget?
For example, use selects the gadget (url), then additional fields appear.
There's workarounds to achieve such functionality (i.e. have a set of parameters for a script per sites page), but it's not possible to do specifically what you're asking. i.e. to put a parameter field on the script gadget interface.
Anyway, that seems like a real good enhancement Apps Script gadgets for Sites could have. You could open an enhancement request on Apps Script issue tracker.