ScriptDB as a
deaddrop box
Passing data between VBA, GAS and JS
what is this about?

•
•
•
•

A short term message store to pass data
between VBA, GAS and JavaScript
Uses the scriptDB AP...
scriptDB API COMPONENTS
Same as using scriptDB as a nosql database
Your
ScriptDB
dispatcher
Your
Your
Your
code
code
VBA/J...
Deaddrop components
Your messageid

Your
Your
Your
code
code
VBA
code

simple
noSql

Your
Your
code
Your
code
JS code
Mess...
DeadDrop class
Related message concepts can be identified by a class
name of your choosing. You can have as many classes
a...
deadDrop handle
You get a handle to a deadDrop class like this
The latest instance for a class
getDeadDrop(yourClass, scri...
deadDrop class Entry
A deaddrop class entry is stored in the registry or as a cookie.
A class entry knows which scriptDBEn...
scriptDB registration - VBA
Private Sub firstTimescriptdbMessages()
Dim scriptdbCom As cScriptDbCom
Set scriptdbCom = New ...
scriptDB registration - JS
function firstTimeMessages() {

// full access to scriptDBPrimer database, oAuth not required -...
Public deaddrop
For testing you may use the credentials for the
‘messages’ scriptDB’ entry
Remember that each class instan...
Usage example
In googleMapping.xlsm, I create a web page
that plots Excel data on a Google Map.
The use case is to retriev...
How it’s done
In VBA, when the mapping app is created, a
new deaddrop conversation is initiated, and
the key is passed to ...
User interaction
// Infobox is instrumented to collect data and write to deaddrop using scriptDB API.
// capture change ev...
Clearing The log
class
googleMapping
googleMapping
googleMapping

key
googleMapping395633308428428
googleMapping3959374939...
The results
Ive used the {subject:xxx} to
determine the original sheet, the
{uniqueId:xxx} and the
{comments:xxxx} to upda...
How to try it
Download googleMapping.xlsm
Set to enable deaddrop in the geoCodingParameters sheet
use custom
enable deaddr...
Next steps
Read all about the scriptDB API
Read more about deadDrop
Contribute to our forum with use case ideas.
Build you...
Upcoming SlideShare
Loading in …5
×

Using script db as a deaddrop to pass data between GAS, JS and Excel

4,319 views

Published on

Here's how to use Google Apps Script ScriptDB as an automated short term data relay for feedback between web sites, Excel and Google Apps Script.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
4,319
On SlideShare
0
From Embeds
0
Number of Embeds
3,223
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Using script db as a deaddrop to pass data between GAS, JS and Excel

  1. 1. ScriptDB as a deaddrop box Passing data between VBA, GAS and JS
  2. 2. what is this about? • • • • A short term message store to pass data between VBA, GAS and JavaScript Uses the scriptDB API for each of these platforms Segregate conversations by the use of keys Uses cookies and registry for authentication purposes
  3. 3. scriptDB API COMPONENTS Same as using scriptDB as a nosql database Your ScriptDB dispatcher Your Your Your code code VBA/JS code Registry /cookie /local storage simple noSql VBA /JS API encrypted oauth2 credentials oauth2 / rest Your Your code Multiple code ScriptDB Your GAS webapp Handler (s) GAS Library API
  4. 4. Deaddrop components Your messageid Your Your Your code code VBA code simple noSql Your Your code Your code JS code Message handler JS/GAS/VBA scriptDB API environment Short lifetime data Short lifetime data Short lifetime data deaddrop Registry ScriptDB credentials Scriptdb cookie/ local storage
  5. 5. DeadDrop class Related message concepts can be identified by a class name of your choosing. You can have as many classes as you want Each conversation creates an instance of a class with a unique key A class instance has a strict lifetime of 24 hours The instance expires and is deleted 24 hours after creation
  6. 6. deadDrop handle You get a handle to a deadDrop class like this The latest instance for a class getDeadDrop(yourClass, scriptDBEntry) A new instance for a class getDeadDrop(yourClass, scriptDBEntry,true) An existing specific class instance getDeadDrop(yourClass, scriptDBEntry,,deadDropKey)
  7. 7. deadDrop class Entry A deaddrop class entry is stored in the registry or as a cookie. A class entry knows which scriptDBEntry to use Before deadDrop can be used, it must be registered to use the scriptDBEntry. This is a one time operation, shared with other scriptDB usage. The scriptDB entry knows how to access scriptDB, which library and which handler to use, and is subject to permissions allowed by the scriptDB entry
  8. 8. scriptDB registration - VBA Private Sub firstTimescriptdbMessages() Dim scriptdbCom As cScriptDbCom Set scriptdbCom = New cScriptDbCom With scriptdbCom.init(, _ "messages", _ ,_ "messagesKey", _ "xliberation", _ False, _ "scriptDBMessages", _ False, _ "https://script.google.com/macros/s/AKfycbzvnq2IZu3JpngnuVxfnPAZYPooVBTULkUyiLFnItfvRxY0NrI/exec") .tearDown End With End Sub
  9. 9. scriptDB registration - JS function firstTimeMessages() { // full access to scriptDBPrimer database, oAuth not required - uses scriptdbrequesthandler new cScriptDbCom().setScriptCredentials( { endPoint : gasHandlerEndPoints.scriptdbrequesthandler, restAPIKey : 'messagesKey', scopeEntry : 'rest', credentialsEntry: 'messages', clientKey:'xliberation', library: 'scriptDBMessages', needDebug: false, needOauth: false } ); }
  10. 10. Public deaddrop For testing you may use the credentials for the ‘messages’ scriptDB’ entry Remember that each class instance expires 24 hours after creation If you find all this useful, you should create your own scriptDb environment
  11. 11. Usage example In googleMapping.xlsm, I create a web page that plots Excel data on a Google Map. The use case is to retrieve data interactively through the map, and update the source Excel sheet.
  12. 12. How it’s done In VBA, when the mapping app is created, a new deaddrop conversation is initiated, and the key is passed to the app. With getdeaddrop(yourClass, "messages", True) With .scriptDb Set job = JSONParse("{'subject':'" & subject & "','info':'xliberation public data for testing'}") .createObject(job).flush job.tearDown End With addDeadDrop = .key End with
  13. 13. User interaction // Infobox is instrumented to collect data and write to deaddrop using scriptDB API. // capture change event - what we'll do here is to update dead drop The deadrop key is passed to the web app and we get a scriptDb handle for it mcpherAddEvent(ci, "change", function(e) { // we have a change - record the update via the dead drop if (pDb) { pDb = getScriptDb(pParams.deaddrop,"messages"); pDb.createObject ({uniqueId: cj.uniqueId, type:'comment', title:cj.title, cj:cj.childIndex, comments:e.srcElement.value}); // empty batch - we'll do it immediately - it'll happen asynch anyway pDb.finalFlush() .done(function(data) { // nothing to do }) .fail(function(data){ alert ("failed to flush to deaddrop"); }); } }, false, true);
  14. 14. Clearing The log class googleMapping googleMapping googleMapping key googleMapping395633308428428 googleMapping395937493918511 googleMapping397080577155843 registered 2/4/2014 11:07 2/4/2014 11:58 2/4/2014 15:08 processed 2/4/2014 12:18 2/4/2014 12:18 Each time a web app is created, this log is updated. Later processing retrieves any data from the deaddrop for each key and updates the original spreadsheet with the data from the deadDrop messsage, marks this as processed and deletes the messages from the deaddrop With getdeaddrop(dr.cell("class").toString, "messages", False, dr.cell("key").toString) ' now we can get all the message data for this With .scriptDb .getObjectsByQuery Set data = .jObject.child("results") Set subject = data.find("subject") With ds.load(subject.toString) …..etc….
  15. 15. The results Ive used the {subject:xxx} to determine the original sheet, the {uniqueId:xxx} and the {comments:xxxx} to update the comments field in the original sheet with data collected by the generated web app.
  16. 16. How to try it Download googleMapping.xlsm Set to enable deaddrop in the geoCodingParameters sheet use custom enable deaddrop deaddrop test TRUE custom code to use if true, then deaddrop conversation will be enabled and lgged - the custom code selected should match this Register your computer to the test drop box locally (on the venues tab) Plot on Google Map, click on some places, add data Process the deadDrop Log Check the comments column on the venues sheet
  17. 17. Next steps Read all about the scriptDB API Read more about deadDrop Contribute to our forum with use case ideas. Build your own scriptDb environment and applications

×