Integrate Pub/Sub in LWC from Omniscript for Toast Notifications
- VlocityGru
- Dec 6, 2024
- 1 min read
Updated: Feb 25
Pub/Sub Event
This event follows the standard Pub/Sub model and can be triggered by Omniscript actions or step elements. Any custom LWC on the Lightning page can listen to this event and respond accordingly.
As an example, I created an Omniscript including three elements. I have enabled the "Pub/Sub" option under the Messaging Framework.
Step 1 - In an Omniscript Action or Step, select the Messaging Framework and check Pub/Sub.

Step 2 - Write an LWC for the toast message.
Note - No need to add anything in HTML unless required.
import { LightningElement } from 'lwc';
import pubsub from 'vlocity_ins/pubsub';
import { OmniscriptBaseMixin } from 'vlocity_ins/omniscriptBaseMixin';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class BQCustomOmniToast extends OmniscriptBaseMixin(LightningElement) {
renderedCallback(){
pubsub.register('omniscript_action', {
data: this.handleOmniActionData.bind(this),
});
}
handleOmniActionData(data) {
if (data) {
this.isLoaded = true;
const toastEvt = new ShowToastEvent({
title: data.title,
message: data.message,
variant: data.variant
});
this.dispatchEvent(toastEvt);
} else {
this.isLoaded = true;
this.failuretoastmsg();
}
}
}
This LWC is more flexible by allowing values (like title, variant, and message) to be passed dynamically from Omniscript.
Please see if you are passing the values either in omniscript action or omniscript step. For more details. Refer - https://help.salesforce.com/s/articleView?id=sf.os_communicate_with_omniscript_from_a_lightning_web_component_1.htm&type=5
Step 3 - Last but not the least.
Displaying the toast message within the Omniscript is straightforward—no additional configuration is needed.
Note - However, if the requirement is to show the toast message on a record page after redirecting from the Omniscript to a Salesforce record page, you’ll need to drag and drop the mentioned LWC onto the FlexiPage. While the LWC will remain invisible, ensuring the event is listened to properly is essential.
Comments