JavaScript code actions

Run_js_code actions allow you to run arbitrary JavaScript code as an action. The code runs the same code as that generated by the blocks action, so if you are not sure about the syntax you can always generate a block first and use that as an example. The code runs in a sandboxed environment, inside an async function body. You can therefore use await at the outermost code level. 

Some variables are in scope that you can use in your action:

  • Table (uppercase T), the class of Saltcorn tables you can use to find tables in which you can then insert, update etc rows. 
  • table (lower case t), the table of the row triggering the action, if available
  • row, the row triggering the action, if available
  • user, the logged in user
  • Actions, an object containing the system actions. The keys are the action names and the values are functions which run the action. Configuration values can be passed in as the argument to the function. TODO example
  • emitEvent, a function that causes an event to be committed when run. The arguments are: emitEvent(eventType: string, channel: string, payload: object) – note, this is three distinct arguments. Only the first argument, the event type, is mandatory.
  • channel, a string denoting the channel of the triggering event available
  • Any functions supplied by plugins are also available