I am supporting CandidateX

CandidateX is a startup that focuses on creating inclusion-focused hiring solutions, designed to increase access to job opportunities for underestimated talent. Check them out if you have a few minutes to spare. They need visibility!

Here’s an app that uses Database abstraction with google apps script via the DataHandler library.

It’s made up of these components

DataHandler library, plus all of the known drivers. It can support any of these databases to store its data

A Google Apps Script webapp that serves up JSONP from the ContentService. To implement your own one, you would copy this.

  • A polling library used by the webapp to access the DataHandler and process requests, votes and dashboards. You would include this library in your webapp.
    A javaScript app to collect votes and for presentation of results with Google  Charts. You would copy this and tailor the CSS to your own style, and link it to your version of the webapp. Alternatively you could use mine and pass the link to your webapp as a parameter.
    A definition language to create question sets.

Setting up a poll

The easiest way to set up a poll is in a spreadsheet. Some concepts.

  • poll – this is an instance of a poll, which is defined by a collection of questions
  • question – this would map to a page of the poll, and has a collection of potential answers
  • answer – these are potential answers to a question
  • table – this is a collection of polls, questions and answers. A table can contain one poll or many. Adding multiple polls in a table means you can share answers and questions between polls. A table is what get stored against a siloID by the DataHandler

Here’s an example of a sheet containing a couple of different polls. Note how answers can be shared between questions and questions can be shared amongst polls. 

Moving the poll to a database.

You can run the whole thing directly from a sheet if you want, or any database supported by DataHandler. If you do use a sheet you’ll need to create an additional sheet in your workbook called ‘sheetname’Answers. Poll answers will be posted there. However, more likely you’ll want to run this from a database, so the first job is to copy your sheet to the database.  Here’s how to replicate this sheet to a parse.com database. [Note: parse.com as now been closed and moved to parseplatform.org. I will update the content of this page an move the back-end to this platform] var parseHandler = new cDataHandler.DataHandler(siloId,cDataHandler.dhConstants.DB.PARSE,undefined,'myscriptdb',JSON.parse(UserProperties.getProperty("parseKeys"))); 
var sheetHandler = new cDataHandler.DataHandler(siloId,cDataHandler.dhConstants.DB.SHEET,undefined, ssid); 
var result = replicate (sheetHandler,parseHandler);
if(result.handleError <0) throw (JSON.stringify(result));

function replicate(fromHandler, toHandler) {

// get data to be copied
var fromResult = fromHandler.query();
if(fromResult.handleError <0) throw (JSON.stringify(fromResult));

// delete existing data
var result = toHandler.remove();
if(result.handleError <0) throw (JSON.stringify(result));
// copy it
var result = toHandler.save(fromResult.data);
if(result.handleError <0) throw (JSON.stringify(result));return result;
} and here’s a snip of what we find in the parse.com browser. 

The Results

Since we’ve decided to use parse.com for this app, that’s where you’ll find the responses. Heading over again to the parse.com browser, 

Setting up your own polling environment

You need the cPoll library – MhwYWpncx2kNyR0sckR24mqi_d-phDA33 and the DataHandler library –  Mj61W-201_t_zC9fJg1IzYiz3TLx7pV4j And you need to make a copy of this, attach the libraries, fix your own default, and publish as a web app.

The client app

I’ve bundled the styles, html and javascript into the same file for simplicity. You should make your own version of this, and modify the url to point at your google apps script webapp.