While creating Running things in parallel using HTML service, in general, I didn’t find this to be an issue, but I came across a few examples where I wanted to describe an Apps Script Service or a library name to use in a profile, which was then passed on to Htmlservice for orchestration, and executed using google.script.run
This kind of objects get lost in translation because they are non-regular JSON type objects.
There is a way around it though. Here’s how
Example
Let’s say that we want to pass the message that a script to be run by google.script.run should use a particular Property Store. If you take a look at Passing data to html service you’ll see how to pass variables to html service. If I wanted to pass something like this
{ parameters: { "siloid": "polymerdbab", "dbid": "xliberation", "peanut": "bruce", "disablecache":true, "driverob": PropertiesService.getScriptProperties() } }
then driverob would get lost in the process of being passed over to html service, yet here I want to pass information to html service that the apps script will later execute using google.script.run should use.
So how to do it ?
By including a sub-property of eval, and then what needs to be evaled as a string, you can postpone the business of resolving the apps script object until later, inside the context of a script being executed by google.script.run
{ parameters: { "siloid": "polymerdbab", "dbid": "xliberation", "peanut": "bruce", "disablecache":true, "driverob": { "eval":"PropertiesService.getScriptProperties();" } } }
The script then just needs to do this to evaluate the parameterized apps script object when it executes. I use the same technique for library names.
if (opts.driverob && opts.driverob.eval) { opts.driverob = eval(opts.driverob.eval); }
Very simple but works great.