Setting appVariable from "Run Code" action

So. I’m struggling a bit with the “Run Code” action.

I have some logic checking a few things, fetching a data model and then trying to set an AppVariable that is of a “data type” defined in the “global data model”. Everything works until I try to set the model. So I’m wondering what the proper way is to update appVariables from code.

E.g. something like

const a = model.find(x => x.user == userId)
if (!!a) {
  appVariablies.a = a // does not work

Also tested with

appVariables.a = a._id


The most appropriate way to update an App Variable would be using the Update Objects action node for App Variables and then the function editor for the variable a. Here you write you logical checks and then return the desired value for a.

Could that be a solution?

If you absolutely need to use the Run Code action node then you may temporary save the value in window

let a = 1
let b = 2

window.runCodeOutput = a * b


And then using the Update Objects action node to update App Variables with temporary saved window value.

return window.runCodeOutput