Start an Action Chain From a Lifecycle Event

Lifecycle events are predefined events that occur during a page's lifecycle. You can start action chains when these events occur by creating event listeners for them. For example, if you want to initialize some component variables when the page opens, you can create an event listener in your artifact that listens for the vbEnter event. You could then set the event listener to trigger an action chain that assigns values to the component's variables.

Before you create an event listener to trigger an action chain, it's important to understand a page's lifecycle, so you know where to plug in custom code to augment the page's lifecycle. Each page in your application has a defined lifecycle, which is simply a series of processing steps. These might involve initializing the page, initializing variables and types, rendering components, and so on.

Each stage of the lifecycle has events associated with it. You can "listen" for these events and start action chains whenever they occur to perform something based on your requirements. For example, to load data before a page loads, you can use the vbEnter event and start an action chain that calls a GET REST endpoint.

Keep in mind that one or more pages make a flow and each flow has its own lifecycle.

This table describes the lifecycle events you can use to start action chains:

Lifecycle Event Description

vbBeforeEnter

Triggered before navigating to a page. Commonly used when a user does not have permission to access a page and to redirect the user to another page (for example, a login screen).

Because this event is dispatched to a page before navigating to it, you can cancel navigation by returning an object with the property cancelled set to true ( { cancelled: true }).

For this event, you can use these variable scopes to get data:
  • $application: All application variables can be used in the event's action chain
  • $flow: All parent flow variables can be used in the event's action chain
  • $parameters: All page input parameters from the URL can be used in the event's action chain

vbEnter

Triggered after container-scoped variables have been added and initialized with their default values, values from URL parameters, or persisted values, and is dispatched to all flows and pages in the current container hierarchy and the application. Commonly used to fetch data.

For this event, you can use these variable scopes to get data:
  • $application: All application variables can be used in the event's action chain
  • $flow: All parent flow variables can be used in the event's action chain
  • $page: All page variables can be used in the event's action chain

vbBeforeExit

Triggered on all pages in the hierarchy before navigating away from a page. Commonly used to warn if a page has to be saved before the user leaves it, or to cancel navigation to a page (say, because a user doesn't have permissions to view that page) by returning an object with the property { cancelled: true }.

vbExit Triggered when navigating away from the page and is dispatched to all flows and pages in the current container hierarchy being exited from. Commonly used to perform cleanup before leaving a page, for example, to delete details of a user's session after logout.
vbAfterNavigate Triggered after navigation to the page is complete and is dispatched to all pages and flows in the hierarchy and the application.
The event's payload ($event) is an object with the following properties:
  • currentPage <String>: Path of the current page
  • previousPage <String>: Path of the previous page
  • currentPageParams <Object>: Current page parameters
  • previousPageParams <Object>: Previous page parameters
vbNotification Triggered when a Fire Notification action is fired by the application.
vbResourceChanged Triggered when an application has been updated. Commonly used to notify the user that they need to refresh to view the updated application.
vbDataProviderNotification Triggered when a Data Provider's implicit fetch fails with an error.

To start an action from a lifecycle event:

  1. Open the Event Listeners tab for the page containing the event you want to trigger an action chain for.
  2. Click + Event Listener.
  3. In the Create Event Listener wizard, expand the Lifecycle Events category and select the event you want to trigger an action chain for. Click Next.
  4. Select the action chain you want to trigger. You can select any action chain that is scoped for the artifact. For example, if you are creating an event for a flow artifact, you can only call action chains defined in the flow or in the application.

    If you want to create a new action chain now, you can click Add Action Chain iconand enter an ID for the new action chain, which you can edit later in the editor. Click Finish.



After you create an event listener, you can click Add Action Chain for the lifecycle event if you want it to start additional action chains.