Run code
Last updated
Last updated
The Run Code action node allows you to run Javascript code from your Apps towards third-party libraries. You may use Appfarm Data and Actions from the code.
You may add external Javascript libraries in Environment Config (Custom Header Tags). These libraries will be accessible from inside the Run Code.
Note that Run Code may run code asynchronously. In order to tell Appfarm when the code is finished running, you always need to finish the code with resolve()
(or reject()
).
If you want to run Actions from inside the Run Code, you must add the Action in the Actions list of the right-side property pane of the Run Code action node. Once added, you may find the Action in the Built in Function Params section of the Run Code function editor. Example: Having an Action Read Projects
added to the Run Code, defined with Function Name readProjects
, you may trigger it from inside the code by writing readProjects()
.
When using Run Code, you may add an App Variable or property of a data source as a Function Parameter. Do not try to update function params directly from the code. Use Actions instead. When adding an App Variable or the property of a Data Source as a Function parameter, a warning is displayed. The same applies if you e.g. add a Data Source as a Function parameter, and then try to modify a property of that data source through code.
Executing an Action from Run Code is a javascript Promise behind the scenes. You need to tell (within the code) if the code should wait for the action execution to finish, or not, before resolving and exiting the Run Code block.
This one is best explained by some examples.
You may also chain multiple actions in sequence