Update Nov2017
UPDATE: parse.com as now been closed and moved to parseplatform.org. I will update the content of this page an move the back-end to this platform
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
|
function testGetItemByUniqueId () { // get a handle for this class var parseCom = cParseCom.getParsed("gasParseData",findRegistryPackage()); // use a valid unique ID to get the data if (parseCom.getObjectById("ZflFVMnczp").isOk()) { Logger.log (JSON.stringify(parseCom.jObject())); } else { throw ("failed to get object:" + parseCom.browser().url() + ":" + parseCom.browser().status() + ":" + parseCom.browser().text()); } } |
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
|
function testparsequery () { // get a number of items that match a query by example var w = getParsed("gasParseData").getObjectsByQuery( {customerid:1},{order:'-value'}); //test if it worked, and do something with the results if (w.isOk() ){ Logger.log( "all is ok"+ JSON.stringify(w.jObject())); } else { throw( "failed to do query:" + w.browser().url() + ":" + w.browser().status() + ":" + w.browser().text()); } } |
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
|
function testparseCount () { // how many records in the class Logger.log (getParsed("gasParseData").count()); // how many records in the class with given query Logger.log (getParsed("gasParseCustomers").count({country:"Libya"})); } |
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
|
function testparseUpdate () { // get some items by query and change the scheme name to something else var w = getParsed("gasParseData").batch(true).updateObjects({customerid:39}, {customerid:1}).batch(false); if (w.isOk() ){ Logger.log( "all is ok"+ JSON.stringify(w.jObject())); } else { throw( "failed to do query:" + w.browser().url() + ":" + w.browser().status() + ":" + w.browser().text()); } } |
For help and more information join our forum, follow the blog or follow me on Twitter