About the Action Chain Code

When you create a new action chain, Visual Builder creates a code file with the basic class declaration for your new action chain. All you need to do is specify the input parameters and return payload types, if any, and to override the run() function. You can do all this through the code editor, visually through the Action Chain editor, or both. You can also create local functions, as needed.

Here’s an example of a simple action chain that returns the sum of its two input parameters:
Description of jsac-action-chain-code-overview.jpg follows
Description of the illustration jsac-action-chain-code-overview.jpg

The availability of a scoped variable depends on where the action chain was created. For example, if an action chain was created at the flow level, the page scoped variable, $page, won't be available.

Note:

It is strongly recommended that you do not use reassignments of context variables (example: const page = $page or const pageVariables = $page.variables), since audits and action chain tests rely on detecting usages of variables using string searches. You should always reference objects fully, for instance: $page.variables.var1.
To call a built-in action, use this format:
Actions.<actionName>(context, {  
   param1: val1,
   param2: val2,
});
To call a custom action, use this format, where the module parameter specifies the custom action's ID:
Actions.runAction(context, { 
   module: ‘<custom-action-ID>’,
   parameters: {
      param1: val1,
      param2: val2,
   },
});
Here are details about the parameters for these APIs:
API Part Details
<actionName> Name of action.
Context The runtime context.
parameters Action-specific parameters object.
<custom-action-ID> Custom actions ID, as set in the custom action’s JSON file.
options Optional; Object that holds the action’s properties for testing or tracing purposes. Currently, it can contain the action’s ID.

For details about the API parameters for each built-in action, see JavaScript Actions in the Oracle Visual Builder Page Model Reference.

Local Functions

Should the need arise to break up the run() entry point function into modular parts, you can create local functions:
Description of jsac-local-function-code-example.png follows
Description of the illustration jsac-local-function-code-example.png