Some simple examples

Because the GAS API is so similar to parse.com - nosql database for VBA, you may want to read that too, which has similar examples. Note that virtually all methods can be chained leading to pretty compact code.

Retrieving an object by unique ID

In parse every object (row) is assigned a unique ID. If you know it you can retrieve that object. You can find it in your parse.com dashboard and substitute in a valid unique ID in the example below

The results
[13-11-29 19:26:23:811 GMT] {"customerid":1,"date":"Sat Aug 10 2013 00:00:00 GMT+0100 (BST)","invoiceid":145,"quantity":9,"value":4230,"createdAt":"2013-11-29T17:25:57.655Z","updatedAt":"2013-11-29T17:25:57.655Z","objectId":"ZflFVMnczp"}

Querying objects

You can query by example, and add options like sort order

The results
[13-11-29 19:16:50:352 GMT] all is ok{"results":[{"customerid":1,"quantity":9,"value":4230,"invoiceid":145,"date":"Sat Aug 10 2013 00:00:00 GMT+0100 (BST)","createdAt":"2013-11-29T17:25:57.655Z","updatedAt":"2013-11-29T17:25:57.655Z","objectId":"ZflFVMnczp"},{"customerid":1,"quantity":10,"value":3900,"invoiceid":246,"date":"7/25/2013","createdAt":"2013-11-29T17:26:00.448Z","updatedAt":"2013-11-29T17:26:00.448Z","objectId":"NgDkL6qg8u"},{"customerid":1,"quantity":3,"value":1560,"invoiceid":151,"date":"5/21/2013","createdAt":"2013-11-29T17:25:57.874Z","updatedAt":"2013-11-29T17:25:57.874Z","objectId":"XDRMUJSbaA"},{"customerid":1,"quantity":2,"value":1050,"invoiceid":175,"date":"8/22/2013","createdAt":"2013-11-29T17:25:58.538Z","updatedAt":"2013-11-29T17:25:58.538Z","objectId":"QjqVyykjip"}]}

Counting objects

You can count total number in the class, or matching a query

The results
[13-11-29 19:20:51:038 GMT] 308.0
[13-11-29 19:20:51:210 GMT] 1.0


Updating Objects

You can do a query, and update some or all of the fields in the matching objects

For help and more information join our forumfollow the blogfollow me on twitter

You want to learn Google Apps Script?

Learning Apps Script, (and transitioning from VBA) are covered comprehensively in my my book, Going Gas - from VBA to Apps script, All formats are available from O'ReillyAmazon and all good bookshops. You can also read a preview on O'Reilly

If you prefer Video style learning I also have two courses available. also published by O'Reilly.
Google Apps Script for Developers and Google Apps Script for Beginners.

Comments