Instrumenting co-operating app

You should now be able to write messages from VBA as described in getting a deadDrop handle from VBA. Now, for our example, we need to enhance Integrating Excel with Maps and Earth,  to be able to retrieve data that a user has entered into a mapping app.

Collecting the text and sending it back

The code for the popup inforBox has been enhanced to include a comments box. Data can be entered here, and it's this data we want to get back to Excel through the deadDrop mechanism. it looks like this.

Here's the code to send it back, which is attached to the change event of the infobox. As you can see it uses scriptDB API for JavaScript to write data asynchronously to scriptDb.

 // capture change event - what we'll do here is to update dead drop
  mcpherAddEvent(ci, "change", function(e) {
     // we have a change - record the update via the dead drop
     if (pDb) {
       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 aynch anyway
      .done(function(data) {
        alert ("failed to flush to deaddrop");
 }, false, true);

The scriptDb handle was already retrieved when the app initialized, using the deadDrop key that was passed over in the data.

 self.setParams = function(qParams){
   // play around with parameters
   pParams = qParams;
   // we can also get deaddrop key from the data
   pParams.deaddrop = pParams.deaddrop || self.getData().framework.control.deaddrop;
   // we'll also open the deaddrop if we need one
   if (pParams.deaddrop) {
        pDb = getScriptDb(pParams.deaddrop,"messages");
        if (!pDb) {
            alert ("could not get a handle for deaddrop " + pParams.deaddrop);
   return pParams;

You can use any operation from the scriptDB API for JavaScript to read or write data using the scriptDB handle associated with this deadDrop key. The only data visible using this key is that associated with this specific conversation.

You can get me on Google plus, Twitter or this forum. See ScriptDB as a dead drop for more on this
For help and more information join our forumfollow the blogfollow me on twitter