Posts

Showing posts with the label lwc

Communicating between Independent LWC in Omniscript

Image
This is a simple example that shows a button that, when clicked, publishes a message. This shows how two separate custom LWCs can communicate with each other inside of an OmniScript. Below is the overall design using the Pub/Sub model. So, lets get started! Step 1: Create a LWC component and use below code to fire events with parameters to pass an omniscript and component to Community Page. Below is the HTML and JS code for reference. SampleLWCComponent.html < template > < lightning-button label = "Send Event" onclick = {handleClick} ></ lightning-button > </ template > SampleLWCComponent.js import { LightningElement } from 'lwc' ; import pubsub from 'vlocity_ins/pubsub' ; export default class SampleLWCComponent extends LightningElement { handleClick ( e ){ let accId = '0015g00000gWY8VAAW' ; pubsub . fire ( "handlePubSubEventChange" , "result" , { "accId" : ac

Import third party JS library in OmniScript Custom Lightning Web Components

 Import third party JS library in OmniScript Custom Lightning Web Components This post explains how to import third-party libraries in omniscript custom lightning web components(lwc). We can not directly import the third party scripts in Lightning web components because Security purpose. We will get error as  "This page has an error. You might just need to refresh it. Error in $A.getCallback() [Assertion Failed!: Scoped imports not allowed when a runtime namespace is specified" Salesforce restrict the importing scripts from third-party content delivery sites like cdnjs, jsdelivr, etc.  Firstly, you need to download the scripts from third-party sites. Then upload the scripts in static resources. Syntax import { loadScript } from 'lightning/platformResourceLoader' ; import { OmniscriptBaseMixin } from 'vlocity_cmt/omniscriptBaseMixin' ; platformResourceLoader  have two methods  loadStyle , and  loadScript.  For both methods return type is Promise. load