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
Just as in parse.com – nosql database for VBA, you’ll probably want to load up some test data from a Google Spreadsheet to a Parse.com class. You’ll find some test data in this workbook – it’s same data as we used from Excel.
Here’s the code you’ll need (after making a reference to your parseCom script as described in parse.com – noSQL database for GAS), to create 2 new classes in your parse.com database.
function testPopulate() { populateFromName ("gasParseCustomers"); populateFromName ("gasParseData"); } function populateFromName (sheetName) { parseCom.populateFromSheetValues(SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName).getDataRange().getValues(), sheetName); }
In the Examples code in the parseCom library you copied there is some code that knows how to populate parse.com from spreadsheet data.
function populateFromSheetValues (values,className) { //this will clear out an existing parse class, and create a new one from a worksheet //we'll use batch mode throughout // need at least a row and a row of headings if (!values || values.length < 2 ) return null; //var parseCom = getParsed(className).batch(true); var package = JSON.parse(UserProperties.getProperty("parseKeys")); var parseCom = cParseCom.getParsed(className, package).batch(true); //clear out existing any existing data parseCom.deleteObjects(); // find out best types for each column dataTypes = []; for ( var j =0,job={} ; j < values[0].length;j++) { dataTypes.push(null); for ( var i=1; i < values.length;i++) { if (toType(values[i][j]) != dataTypes[j]) { dataTypes[j] = dataTypes[j] ? "string" : toType(values[i][j]); } } } // populate parse for ( var i=1; i < values.length;i++) { for ( var j =0,job={} ; j < values[i].length;j++) { var v = values[i][j], k = values[0][j]; // deal with where we have to take a guess at the type if (dataTypes[j] === "date") { job[k] = {"__type":"Date","iso":v}; } else { job[k] = dataTypes[j] === 'string' ? v.toString() : v; } } if (!parseCom.createObject(job).isOk()) throw("failed to create object:" + w.browser().url() + ":" + w.browser().status() + ":" + w.browser().text()); } parseCom.flush(); Logger.log(parseCom.count() + " in class" + className); }For more on this see parse.com – noSQL database for GAS.
For help and more information join our forum, follow the blog or follow me on Twitter