One problem with running things from html service with google.script.run is that you don’t have access to logging and execution log, so it’s difficult to debug. I like to run my profile components inline first to make sure they work. Here’s how you can simulate running this stuff from google.script.run in the context of a normal apps script.
This function takes your profile and executes the named function, and passes over the data just as would happen if it was called from google.script.run.
1 2 3 4 5 6 7 8 9 10 |
/** * from a profile, emulates running it from the sidebar * @param {object} profile the profile * @param {data} the data to pass * @return {object} whatever the function would return */ function inLineTest (profile,data) { var evalable = profile.functionName + "(" + JSON.stringify(profile.options) + (data ? ("," + JSON.stringify(data)) : "") + ")"; return eval(evalable); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
function smallDbTest() { // i'll do properties var p = cUseful.clone(dbDataStoreParameters()); // clear the sheet var d = inLineTest (dbAsyncClear (p.parameters, p.driver,p.clearProcess),null); // some test data var d = inLineTest (dbAsyncTestData (),null); // reduce var d = inLineTest (dbAsyncReduce(),[{results:d}]); // the tests var d = inLineTest (dbAsyncExecute (p.parameters,p.driver,0,1,p.process),[{results:d}]); // reduce var d = inLineTest (dbAsyncReduce(),[{results:d}]); // log var d = inLineTest (dbAsyncLog(p.driver),[{results:d}]); } |
1 2 3 4 5 6 7 8 9 |
function dbAsyncReduce () { return { "name": "reduction", "functionName":"reduceTheResults", "debug":false, "options":{ } }; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
function dbAsyncProfiles(dbParameters, dbDriver, process, clearProcess) { var CHUNKS = 4; var profile = []; // clear the db var profileClear = [dbAsyncClear (dbParameters, dbDriver, clearProcess )]; // get the test data var profileTest = [dbAsyncTestData ()]; // reduce the test data var profileReduction = [dbAsyncReduce()]; // get and process all the messages var profileSheets = []; for (var i =0; i <CHUNKS;i++ ) { profileSheets.push (dbAsyncExecute (dbParameters,dbDriver,i,CHUNKS,process)); } //Log the results var profileLog= [dbAsyncLog (dbDriver)]; profile.push( profileClear, profileTest, profileReduction, profileSheets, profileReduction, profileLog ); return profile; } |
For more snippets like this see Google Apps Scripts snippets