- Script parameters are sent via a global “data” json object. You retrieve the value of the parameter by simply retrieving it from the data object – i.e. myParm = data[“myParm”];
- You don’t technically “return” from a Cloud Code script. The last line of the script will instead simply declare the final object to be evaluated as the script’s return — this will be clearer after we do an example or two.
- Scripts can be quickly tested via the API Explorer. The API and S2S Explorers make it very easy to test your Cloud Code. Simply go to Design | Cloud Code | API Explorer, then authenticate a session, and then call your script using the Script service and the appropriate Run Script operation. The explorer will even pull your example parameters from the script definitions, so it’s pretty quick and simple to execute.
- Scripts are versioned. Every time you save a new copy of a script we backup the older version. You can revert to an older script at any time.
- Scripts have a “watchdog timer” that ensures that they don’t run too long. This is essentially to protect the performance of the overall system from run-away scripts. The timeouts for scripts are set individually. The default timeout for a script is 10 seconds, but can be set to up to 60 seconds in the timeout dropdown. Note, brainCloud does allow for running longer-term background scripts – just reach-out to us to enable the setting of longer timeouts.
When writing Cloud Code scripts, there are some key limitations to keep in mind:
- Each script is limited to a single entry point. This means that essentially the “mainline” of a script is run whenever the script is called.
- Access to external libraries is limited. We’re looking to add access to popular libraries like Moment.js in the future.