ScriptDb and Google Visualization API - google-apps-script

I have a web app that data is submitted from a Ui embedded in a Google Site and saved in a spreadsheet. I am thinking about switching to scriptDB instead, but I am unsure about querying and displaying data dynamically. The last time I checked it was not possible to refresh a sites page from within a script, so as a work around I wrote a .html page with javascript that accesses the spreadsheet via the key and uses the Visualization DataTables to produce a quick and nicely formatted query. I would like to retain this functionality if possible. Could anyone make some possible suggestions?
Regards,
Shawn

This is doable today via UiApp (see the Charts api, and note that you can add a Chart to a UiApp).

To auto refresh:
You can use CheckBox.setValue(value, fireEvents) - but you may hit quota issues (there is an example somewhere around). If you hit quota issues, then I suspect HTML service is your best option. It also gives you better control.

Here is an open item requesting expanded Charts service integration with Gviz.
Although, there is limited integration at present, it needs to be expanded to group variables in tables to facilitate basic count and sum operations.
I suggest you “star” the issue to vote for it and to be notified of new developments.

Related

Transform Old Google Spreadsheet Code

I used this code to insert documents directly into a Google spreadsheet without having to upload files and then create hyperlinks. However, as google moved to the new spreadsheet...
Warning: The UI service was deprecated on December 11, 2014. To create user interfaces, use the HTML service instead.
So know I need help fixing lines like; var app = UiApp.getActiveApplication();
If someone could clarify the different types of programming direction you could take this project from, that would also be very helpful, I am not really sure if I need to work with Javascript or HTML now.
The answer to your question will depend in large part on how you are using UIApp. In most cases it's not as simple as changing a few lines of code but more of a script redesign.
If you are using it to create a custom user interface, your path forward would be to rebuild your interface as HTML/Javascript and serve it to the user with HTMLService. The service is overall much more powerful/flexible and provides a better end-user experience but it means rewriting how your script works. If you want to take a look at a helpful example on how the HTML Service works take a look at the HTML Service Guide or this quick-start example of an add on.
You can still link this html interface with your script using the google.script.run service but you will need to redesign your code/application to work with the new input methods. The good news is although UI service will sunset on June 30, 2015, "Service will no longer appear in autocomplete, although existing scripts should still function."
It's worth considering alternate ways to accomplish the same goal. The best way to do that is to start by asking "What is the intended use of this script? What problem does it solve?" There may be a better way to accomplish that task which may not even involve updating the script.
This is not related to the new spreadsheet version, the message you get is because UiApp has recently been deprecated.
A Google search would have shown you a few tracks to find your way.
One of the best I found is this one from Sandy Good : Google apps script UI services to HTML services
It shows a typical example of conversion to HTMLService.

Real-time Changes to Google Document / Spreadsheet / Presentation

Is it possible to get a real-time notification (without extensive polling) for changes made to a Google document (document / spreadsheet / presentation)? If so, what is the model structure (if that makes sense)? Any pointers to documentation or samples would help!
The documentation at https://developers.google.com/drive/manage-changes gives an API call that returns instantly and tells you whether there have been any changes since the last one. However, this is useless you want to know almost as soon as a change has been made -- you would have to make back to back API calls every second or sooner and churn a lot of resources. The Drive Real-time API in contrast gives a way to be instantly notified of any changes without extensive and frequent polling. It does this with an HTTP call that "hangs" until there is a change ready (or a timer expires). This is a classic long-poll technique.
My question is whether such a facility exists for Google Documents / Spreadsheets / Presentations. Or is it available only for custom app-specific files other than these standard ones. If it is not available, are there any plans for making them available?
Thanks in advance!
In my knowledge - the answer is "NO". I have tried this before and could only do it with the timed polling. The API is limited to tell you only when you ask, not when something happens.
I thought of a code that is embed into document and does a self broadcast to a specific URL or some listener. My experiments were with Google App Scripts. Detail idea is to create a custom function that gets triggered on the 'Save' event. But I could go no further as there is nothing enough in documentation as per me to achieve this specific goal.
On the timelines for this availability, there are questions in the scripts forum on this, but none replied on these lines.
It looks like it, see https://developers.google.com/drive/v2/reference/changes
it has examples too
edit:
https://developers.google.com/drive/manage-changes
more info about tracking changes
The answer, I'm afraid, is no. There is currently no way for you to be notified by email when a change is made to a Drive text document. This function is available for spreadsheets, but not for text files. If your document is public, you ccan subscribe to its RSS feed to view changes, or use the Tools -> Revision History function in Drive.
There is one downloadable program, googledocsnotifier --information--, which emails you when edits are made and allows you to open the doc that was edited, but it appears that it only works when you are online. You can download it here.
Hope this helps!

Is there a way of seeing the script code for an action I have performed?

I am new to writing scripts in Google Apps. I am trying to script various actions in Google Docs which previously I would have done through the main user interface. Is there a way of "recording" such actions as they are carried out, analogous to recording a Macro in Excel?
For example, I am creating a Form in Google Docs. Using the main interface, I can add an Image item and upload an image from another source (Google Drive, my desktop, etc.), but I can't work out the script code that would perform this same action. Is there any way to output the script that would have carried out the same action that I have just performed?
Many thanks.
Currently, you cannot 'record' a macro.
There is an issue in the Issue tracker (issue 650) where Google have mentioned that it is not feasible at the moment (Jul 2010). You may star the issue to register your interest to the enhancement request.
I think the real issue is that the GApps scripting functions are manipulations of the underlying object model of the document. The UI also manipulates the underlying object model, but no one has yet created the functions to emulate the UI in GApps script form. Recording the actions would then be a separate step and converting the recorded actions into GApps functions would be yet another step.
So you need to be clear: is your goal to be able to record and play back UI actions, or is your goal to be able to upload an image into a GDoc? You asked about recording and that's the answer you got. Maybe if you asked about how to use GApps to add an image to a GDoc, you would get a more useful answer.
My own personal question would be:
I haven't figured out how to use the GApps documentation very
efficiently yet. I do a lot of fruitless hunting. How do I find in the
docs how to add an image to a GDoc?
I hope this helps.

Does Google docs have content controls?

I have a question regarding Google Docs and content controls (if there are any?)
We have a system that lets users design a MS Word doc with content controls (rtf text, comboboxes etc) and assign an ID to the control so that our system can pull the ID and register the answer. The data is then saved in a database.
What is a content control?
So my question is, is there any way to acheive this with google docs? I've been looking around but were unable to find a satisfying answer.
I would like to present users with a document in google docs that they fill in and return to me.
It does not have to be controls, but maybe sections that I can identify and pull content from with googles API.
You have couple of options:
Use the Form option in Google Spreadsheet. Check their tutorial at: http://support.google.com/docs/bin/answer.py?hl=en&answer=87809. They have a nice set of controls (checkbox, multiple choice...). You are getting the benefits of automatic update of the forms into the spreadsheet; no need to create a database...
A bit more complex (but still simple) option is to use Google Apps Script to write a small application GUI that works with the spreadsheet. You get more control over the GUI and all the benefits of automatic data storage, triggering events on each form submission etc. Check out this advanced tutorial: http://code.google.com/googleapps/appsscript/articles/building-sites-app.html

Google Form API?

I would like to (programmatically) convert a text file with questions to a Google form. I want to specify the questions and the questiontypes and their options. Example: the questiontype scale should go from 1 to 7 and should have the label 'not important' for 1 and 'very important' for 7.
I was looking into the Google Spreadsheet API but did not see a solution.
(The Google form API at http://code.lancepollard.com/introducing-the-google-form-api is not an answer to this question)
Google released API for this: https://developers.google.com/apps-script/reference/forms/
This service allows scripts to create, access, and modify Google Forms.
Until Google satisfies this feature request (star the feature on Google's site if you want to vote for it), you could try a non-API approach.
iMacros allows you to record, modify and play back macros that control your web browser. My experiments with Google Drive showed that the basic version (without DirectScreen technology) doesn't record macros properly. I tried it with both the plugin for IE (basic and advanced click mode) and Chrome (the latter has limited iMacro support). FYI, I was able to get iMacros IE plug-in to create questions on mentimeter.com, but the macro recorder gets some input fields wrong (which requires hacking of the macro, double-checking the ATTR= of the TAG commands with the 'Inspect element' feature of Chrome, for example).
Assuming that you can get the TAG commands to produce clicks in the right places in Google Drive, the approach is that you basically write (ideally record) a macro, going through the steps you need to create the form as you would using a browser. Then the macro can be edited (you can use variables in iMacros, get the question/questiontype data from a CSV or user-input dialogs, etc.). Looping in iMacros is crude, however. There's no EOF for a CSV (you basically have to know how many lines are in the file and hard-code the loop in your macro).
There's a way to integrate iMacro calls with VB, etc., but I'm not sure if it's possible with the free versions. There's another angle where you generate code (Javascript) from a macro, and then modify it from there.
Of course, all of these things are more fragile than an API approach long-term. Google could change its presentation layer and it will break your macros.
Seems like Apps Script now has a REST API and SDK's for it. Through Apps Script you can generate Google Forms. This API was really hard to find by trying to google for it and I haven't yet tested it myself, but I am going to build something with it today (hopefully). So far everything looks good.
EDIT: Seems like the REST API I am using works very well for fully automated usage.
In March(2022) google released REST API for google form. API allows basic crud operation & also added support for registering watches on the form to notify whenever either form is updated or a new response is received.
As of now (March 2016), Google Forms APIs allow us to create forms and store them in Google Drive. However, Forms APIs do not allow one programmatically modify the form (such as modify content, add or delete questions, pre-filled data, etc). In other words, the form is static. In order to serve custom, external APIs are needed.