Use a Google Docs Spreadsheet as a datasource for a dynamic Google Sites webpage - google-apps-script

I have a Google Form that feeds a Google Docs Spreadsheet. I'd like to--in turn--have that Google Docs Spreadsheet feed a webpage.
In plainer English, babysitters fill out the form to sign up to be in our community's Babysitter Directory. The spreadsheet houses all of the data. I'd like to code a webpage to pull selected bits of the data for the online directory.
I've tried doing a separate sheet in the spreadsheet, using a QUERY to select the columns that I want to include (and the order in which I want to include them), publishing that sheet to the web, then embedding that sheet into the webpage in an iFrame. And that works.
But even with the QUERY, there are SO many columns that users need to scroll WAY over to the right to see all the data for each babysitter. It's unwieldy.
What would be way better would be if I could break the data for each entry over multiple lines and do some nice formatting for a directory, rather than just a linear spreadsheet. So that, essentially, each babysitter's "entry" in the directory is more than 1 line long. Does that make sense?
If I was working in Office, I would know exactly what to do: use the Excel spreadsheet as the datasource for a Word Mail Merge and I would put move the fields around on the page to make it all look good.
And, to be sure, if I can do this in a Google Doc, then embed the Doc into the webpage, that's fine, too. But I would think there's some way I can do it directly in the Google Site?
Can I?
If anybody has even just a reference page for me to take a look at, I'd appreciate it.
Thanks!

Are you trying to do this in Google Sites? If so, you can embed the entire spreadsheet on the page, but if you only want certain columns, you can try inserting an Apps Script widget on the page.
You need to know how to write a Google Apps Script that will run JS functions and render HTML, here is a tutorial
To create the Script that can run on your page, go to:
More > Manage site > Apps Script > Add new script
Here's also a link to how to interact with Spreadsheet data.

What you want to do is more or less a database interface that uses a spreadsheet as 'data holder', depending on your programming skills it can be quite easy or very hard...
Here is an example of such a webapp, its has probably too many fields and features but the general idea is the same (a quick search tool and a window to show results).
It that what you had in mind ?
If so I can share the code to help you to get started but if you are not familiar with javascript it will probably need too much effort to get through.

Related

SelectBox in Google Script?

I am a little bit new to Google Script so apologies if my question is silly. I have the following user scenario:
- on a monthly basis I get standard file from on of my departments
- I save the file on Google Drive and automatically copy certain information to my Sheets that I use to analyse this information
- I finished the code that does the copy, selection, etc.
I am struggling with the first piece - some sort of SelectBox that I would use to select source file. I can write code that will search Google Drive and display potential files, display them in ListBox, but maybe there is other way (the simpler the better). What would you recommend here?
Google has nice Box that shows up when you try to copy sheet into other Sheets document, but it seems not to be avaialble for Script.
Any help is much appreciated.

Is there a way to run scripts when someone is answering to a Google Form?

So, here at the company I work for we usually manage the workforce weekends schedules in a very manual way using Excel, and then upload a pdf version of the sheet in our intranet so everyone can see their own schedule for the rest of the month and look up for swaps if they need to.
The problem is that the workforce recently has grown up a lot and we're spending a lot of time validating and reuploading the schedule everytime we need to do the shift swaps. So I decided to start a project using Google Sheets and Google Forms, so we could just show iFrame of the sheet in the view mode, and their supervisors could make their swaps via a google form, which would update the sheet and they could see it happening on-the-fly, I guess.
Now that I gave you some context, what I really need is to discover if there's actually a way to accomplish what I'm trying to, because I already stuck once realizing that the script running from a Google Sheet only works with edit permissions (I need to no one have permission to change manually the sheet and preferably not even needing to link account to Google), but now I realized even when scripting inside of the form it doesn't run when people are answering to the form, but only in the edit mode, which I think it's useless for me since questions should be dynamic (the form would look for the available weekends and employees in the sheet using some validations).
For example, the code below runs when I open the form in Edit mode, but not when I open the shared link:
function onOpen() {
var ui = FormApp.getUi();
ui.alert('test');
}
So, my question is if this project is possible using Google Scripts and the suite, if there's some kind of option or permission I'm missing to make it work, or if it's worth I try to do it using an not inbound countainer script, or maybe HTML Service, or if I should forget Google and look for another tools for this job.
Thanks.

Uploading an XLSX converting and replacing a current spreadsheet

Just a general question, I would like to create a user upload form that would convert an .xlsx to the corresponding Google Sheets version and then replace a currently existing sheet on my drive. The main question and aspect that I'm not sure is achievable is replacing a current google sheet. Is a project like this even achievable in a reasonable manner? The reason I want to replace it is because the KeyID for that sheet is used in a couple other app scripts for a website. Thanks for the suggestions and advice.
Yes, this is possible. About being "reasonable", well... I think it is, it's not a single line script, but this is not the most simple task either.
But from what I understood from your use-case (other app script for a website), I think it's better if you enhance your other scripts to either look for the newest sheet on a given folder or fetch the ID from somewhere that you can update from the "form upload" script. Also, by doing this, you'll avoid getting inconsistent data in the middle of an update.

Google Forms Script to Move User to New Page in the Form

If I have a Google Form, how might I use Apps Script to:
1.) Get the user's responses to questions on one page of the form
INTERJECT SCRIPT LOGIC
2.) (pause) the form and have the script activate to:
process their results
depending on the result of that processing, move them to a different page
Basically, I want to have the script analyze the results of a particular page, and redirect them to a new page depending on the results to multiple answers. There is a redirect utility in the form itself, but it only works for the result of one question. I have two questions that I need to ask, and based on both of those answers, move them to a new page.
I know that I can create Items that have a PageNavigationType as seen here, however, this is for a single item only. There is also no setPageNavigationType for Items, so I'm wondering if this is even possible to do dynamically as a user is filling out the form?
Hate to be the one to give the bad news, but that's not possible.
Google Apps Script only helps with the Form creation process (and editing), it's not possible to do anything while the user is filling it, period.
Also, it can only do programatically what you can do manually on the Form interface, it's useful only to help you automate things that would be cumbersome to do manually. For example, adding a long list of options to a question, or helping you generate and email hundreds of similar Forms. Or just really creating quick quizzes or some other forms that you have to create every week, etc.
Just to be completely clear to other users that might read this. It's not possible to do anything with Apps Script for Google Forms that you can't already do manually. Apps Script does not add any new or hidden features to Google Forms.

How to build a decision support app with Google Apps Script (forms with subquestions)?

I want to create an app which helps newbie employers to take some simple decisions. So, using their answers to a form, the app asks new questions based on previous responses, something similar to a decision tree. Is Google Form a good alternative to implement this? (something like this suggested here, but with more questions:
Are there alternatives based on Google Apps Script?
What you need is a Google Form with a lot of questions, whose answers redirect to different pages in the Form.
You can also use Google Apps Script Forms Service to create Forms through code (and you can use previous responses in old Forms to generate new content for new Forms dynamically).
A typical example of this would be:
Create a Google Form with several questions with redirects based on answers (decision trees).
Have the responses to that form go to a response Spreadsheet.
Run a script on the response Spreadsheet to generate new content using the Forms Service within Google Apps Script (or do this manually; both work).
Send out the new Form to employees by email (you can use Gmail Service to accomplish this) or however you prefer.
--> and repeat the process as needed.
At my work, I use Google Forms with redirects and scripts on the response Spreadsheets in order to process faculty requests using Google Apps Script, so this is definitely possible!
However, it should be noted that Google Apps Script cannot be used to dynamically generate content for Forms while the user is filling it out. See my question here.
I don't feel like typing a mass of code here, but there are two ways of accomplishing this (both of which would require a lot of script code):
You could potentially accomplish this by making a web app that automatically dumps the responses into a spreadsheet (limited space) or a document (which doesn't have to be human-readable). This won't give you the same UI, but it would work, assuming you are familiar with making web apps in the first place.
You could make a multi-page form that you could write some code to direct the person upon selection of whatever choice they make to go to the correct page. This other question may serve of use if you want to go this route (it likely will be a bit easier).