Omnistudio Pubsub

lightning-omnistudio-pubsub

Provides a lightweight publish-subscribe mechanism for sibling Lightning web components to communicate without direct references.

For Use In

Lightning Experience, Experience Builder Sites

Share data and pass messages between components that don’t have a parent-child relationship using the lightning/omnistudioPubsub module. Using this module, you can register, unregister, and fire events dynamically.

In Omnistudio, you can trigger a pubsub event from an action on a Flexcard, or communicate from an Omniscript to a Lightning web component. Omnistudio is available to select Industry Cloud customers.

To use Omnistudio PubSub directly in your custom Lightning web component, use the lightning/omnistudioPubsub module. The lightning/omnistudioPubsub module is a wrapper for the Omnistudio PubSub property.

To use the pubsub functionality, import pubsub from the lightning/omnistudioPubsub module in the component.

1import pubsub from "lightning/omnistudioPubsub";
2
3// Register a callback
4pubsub.register("eventName", callbackObject);
5
6// Fire an event
7pubsub.fire("eventName", action, payload);
8
9// Unregister a callback
10pubsub.unregister("eventName", callbackObject);

This utility component doesn’t have a template and can’t be directly accessed via Lightning App Builder. A custom component that uses the utility component can be accessed via Lightning App Builder. To make your component available in Lightning App Builder, see Configure a Component for Lightning App Builder. To make your component available in Experience Builder, see Configure a Component for Experience Builder.

This example uses the lightning/omnistudioPubsub module to register, unregister, and fire a test event dynamically.

1import omnistudioPubsub from "lightning/omnistudioPubsub";
2
3export default class TestComponent extends LightningElement {
4  connectedCallback() {
5    this.handleMessage = {
6      testevent: this.handleTestEvent.bind(this),
7      testeventnew: this.handleTestEventNew.bind(this),
8    };
9    omnistudioPubsub.register("testchannel", this.handleMessage);
10  }
11
12  handleTestEvent(event) {
13    //Some logic here
14  }
15
16  handleTestEventNew(event) {
17    //Some logic here
18  }
19
20  disconnectedCallback() {
21    omnistudioPubsub.unsubscribe("testchannel", this.handleMessage);
22  }
23}

Public Methods 

register(eventName, callbackobj)

Register a set of event handlers to a specific channel.

ParameterTypeDescription
eventNamestringThe name of the event to register for
callbackobjobjectThe callback object to register

unregister(eventName, callbackobj)

Unregister your set of event handlers from a channel. To avoid memory leaks or potential errors, always unregister event handlers when a component is disposed or disconnected. In addition, to properly unregister event handlers, pass both the channel name and instance of your event handler objects.

ParameterTypeDescription
eventNamestringThe name of the event to unregister from
callbackobjobjectThe callback object to unregister

fire(eventName, action, payload)

Fire an event over a specific channel to all registered handlers. The payload can be any object. However, make sure your handlers expect that particular structure. For example, if you intend to send a JSON object with various keys, your handlers should know what those keys are.

ParameterTypeDescription
eventNamestringThe name of the event to fire
actionstringThe action to perform
payloadobjectThe payload data for the event

Attributes 

NameDescriptionTypeDefaultRequired
directionText direction.string'ltr'
displayString translated label to identify if we need to display as button.string
inline-labelLabel when displayed as button.string'DefaultLabel'
inline-variantButton variant when displayed as button.string'brand'
languageLanguage in which the omniscript was created.string'English'
lwrDetermines which component to use for rendering. When true, uses runtime_omnistudio-generated-omniscript-lwr for LWR compatibility. When false or not provided, uses the standard runtime_omnistudio-generated-omniscript.booleanfalse
offlineWhether this omniscript should use the offline renderer. When true, delegates to runtime_omnistudio_offline-offline-renderer which is suported runtime for offline usagebooleanfalse
prefillPreload Data JSON.Object
record-idRecordId of the Salesforce Object.string
sub-typeSubtype of the omniscript.string
themeUI Theme of the omniscript.string'slds'
typeType of the omniscript.string