Store data in scriptdb

Create a module that stores some test data in a public scriptdb.

In Hosting your public scriptdb you will have created a public scriptDB,  Here's how to store data in a public scriptdb. We are going to create a website favorites list and store in for public access. Here's the data.
{ favorites :
  [{ name : "excel liberation" , url: "ramlings.mcpher.com"} , 
   {name:"liberation blog", url: "excelramblings.blogspot.com"}] }  


Add the project key for your public scriptdb module

In Hosting your public scriptdb you will have generated a script that we need to access. You need to add that library to your storeinscriptdb  module you created earlier,  in addition to the one you added in Using the mcpher library in your code. Goto resources resources/manage library and add it.
google apps script adding library


Adding data to the library

This module is going to remain private, since it's purpose is simply to add test data to a public scriptDB. It's likely that you would make a UI for this to collect data from a form. However for our test, we are going to write it with a module. Copy in this code without modification to your storeinscriptdb  module and run storeFavorites. Note this will go through an authorization dialog the first time you run it, so you'll need to run it twice.

function storeFavorites() {
  createScriptEntry ( "favorites", 
    [ { name : "excel liberation" , url: "ramblings.mcpher.com"} , 
      { name : "liberation blog", url: "excelramblings.blogspot.com"}
    ] );
}

function createScriptEntry(name, o) {
  return mcpher.createStuff (name, pubstuff.publicStuffDb(), o );
}

function showAllpublic() {  
  mcpher.showAll( pubstuff.publicStuffDb());
}

Testing

In this case for testing, if you run showAllPublic(), you should get something like this result in the log

{
    "siloId": "favorites",
    "help": "for details see ramblings.mcpher.com",
    "timeStamp": 1352116189719,
    "myStuff": [
        {
            "name": "excel liberation",
            "url": "ramblings.mcpher.com"
        },
        {
            "name": "liberation blog",
            "url": "excelramblings.blogspot.com"
        }
    ],
    "userStamp": "bruce@mcpher.com"
}

For help and more information join our forum,follow the blog or follow me on twitter . Now take a look at the next step in step by step guide to delegating to Google Apps Script.



Comments