Flexcards have the ability to trigger and listen to two kinds of events: Custom and Pubsub events.
Custom Events serve as a way to exchange information between a child and its parent. This can happen between a child Flexcard and its parent Flexcard, or between an element and the Flexcard it belongs to.
Pubsub Events enable communication between two distinct components. This could be between two different Flexcards located on the same Lightning page, known as sibling Flexcards, or between a Flexcard and an Omniscript.
Here, we’ll explore how to establish communication between two separate FlexCards on the same Lightning page using the Pubsub event.
The process includes the following steps:
- Develop a Flexcard that triggers a Pubsub event.
- Create another Flexcard that is configured to listen for the Pubsub event triggered by the first Flexcard. Once detected, this Flexcard will execute a specified action in response.
To initiate the process, Create a new Flexcard and integrate a Select input element. This Flexcard is designed to trigger a Pubsub event.
Click on the “Add Action” button located within the Properties section to initiate the process. This action will prompt the opening of the Action Properties modal. Enter the required details as outlined below.
Action Type: Event
Event Type: PubSub
Channel Name: DisplayFilteredContact
Event Name: FilterContact
Note: When configuring Pubsub and custom events, it’s essential to avoid using reserved event names and channel names for specific purposes. Please refer to the article “FlexCards Reserved Event and Channel Names” for the list of reserved names.
For Input Parameters, include the data to be transmitted in a key-value format.
For instance:
- Key: SelectedContact
- Value: {element.value}
Here, {element.value} represents the local context variable holding the value selected in the ‘Select‘ input element within the Flexcard.
Next, we proceed to create another Flexcard. This particular Flexcard is configured to listen for the Pubsub event that was triggered by the previously established Flexcard. Upon detection of the event, it executes the necessary action as specified.
Now, We Will Create an Integration Procedure named IP_GetFilteredContact, which is responsible for retrieving a list of Contacts associated with an Account. This Integration Procedure will serve as a data source for the Flexcard.
In this context, DRGetContactsDetails refers to a DataRaptor Extract Action tasked with fetching all Contacts associated with a specific Account. This operation is carried out based on the AccountId filter value passed to the DataRaptor.
Now, add The Set Value Action FilterContact utilizes the outcome of the DataRaptor Extract action.
A new element is introduced in the Element Value Map with the following details:
Element Name: FilteredContact
Value: =IF(%ApplyFilter%, LIST(FILTER(LIST(%GetContactDetails%), ‘Status == “‘ + StatusValue + ‘”‘ )), LIST(%GetContactDetails%))
In the function, %ApplyFilter% serves as the condition.
- If %ApplyFilter% is provided as false, all the cases retrieved from the DataRaptor Extract Action will be assigned to the element.
- However, if %ApplyFilter% is true, only the Contact matching the particular Status (determined by the dynamic input StatusValue) will be assigned to the element.
The Response Action RASendToFC dispatches the output generated by the Set Value action as the response of the Integration Procedure.
Subsequently, within the ‘Setup‘ tab of the Flexcard, the Integration Procedure is included as the designated Data Source.