In Instrumenting co-operating app I showed how a web app might create some data in a dead drop to pass back to VBA. In my example, there are many worksheets, each of which may have outstanding messages, so I need a way to track responses I might be expecting from particular deadDrop keys. I've created a log that gets automatically updated each time a web app is generated with its deadDrop key. From time to time I can run a process that examines all the outstanding message keys and checks for messages. You don't need to do this of course - it's just an easy way to handle backlogs of requests and storing their keys Opening the logThis a one liner Public Function getDeadDropLog() As cDataSet Dim ds As cDataSet Set ds = New cDataSet Set getDeadDropLog = ds.load("deadDropLog") End Function to get a sheet that looks like this Adding to the logHere I create a deaddrop handle and update the log with the new outstanding request. The expectation is that whoever called this will pass the generated key on to the co-operating app. Public Function addDeadDrop(subject As String, Optional yourClass As String = "googleMapping") As String ' Example showing how outstanding requests might be logged Dim job As cJobject, ds As cDataSet With getdeaddrop(yourClass, "messages", True) ' write a message for information With .scriptDb Set job = JSONParse("{'subject':'" & subject & "','info':'xliberation public data for testing'}") .createObject(job).flush job.tearDown End With ' add to spreadsheet log Set ds = getDeadDropLog ds.headingRow.headings("class").where.Offset(ds.rows.count + 1).value = .scriptDbClass ds.headingRow.headings("key").where.Offset(ds.rows.count + 1).value = .key ds.headingRow.headings("registered").where.Offset(ds.rows.count + 1).value = Now ds.tearDown addDeadDrop = .key .tearDown End With End Function Processing the logMy example is fairly lengthy, but the process is straightforward. Check the log for unprocessed entries, get the data if any, update the log entry, delete the message Public Sub processDeadDrop(Optional redo As Boolean = False, Optional deleteWhenProcessed As Boolean = True) ' example showing how you might take feedback data for an entire workbook Dim job As cJobject, ds As cDataSet, dr As cDataRow, data As cJobject, _ subject As cJobject, good As Boolean, dsDrop As cDataSet ' first step is to get all the known requests Set dsDrop = getDeadDropLog For Each dr In dsDrop.rows ' only do the unprocessed ones or override If redo Or IsEmpty(dr.cell("processed")) Or Len(dr.cell("processed").toString) = 0 Then With getdeaddrop(dr.cell("class").toString, "messages", False, dr.cell("key").toString) ' now we can get all the message data for this .. do something with the data here ..... End With End If Next dr dsDrop.column("processed").Commit dsDrop.tearDown End Sub 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 forum, follow the blog, follow me on twitter |
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > Things that have been deprecated > Google Apps ScriptDB > ScriptDB as a dead drop >