Vlocity Facts #43 || How to pass recordId from Utility Items to Omniscript by using LWC

In one of the previous post I have discussed about how to launch omniscript from Utility Items. [How to call Omniscript from Utility Items]

If we need to refer current page recordId in omniscript and perform logic, we can't achieve that by using standard method mentioned in above link. To overcome this we need to launch omniscript from the LWC. Let's see how to launch omniscript from LWC.

1. Create Omniscript according to your requirement. For example I'm fetching account details and displaying.

2. Pass ContextId as the Data Source to DataRaptor.

3. From top right side of the omniscript click on how to launch button and copy the first link. We will use that in LWC.4. Now create LWC to Launch the omniscript and paste the copied URL as shown.5. Now open js file of the LWC and copy below code.

import { LightningElement,wire, track,api } from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { OmniscriptBaseMixin } from "omnistudio/omniscriptBaseMixin";
export default class InvokeOsFromLWC extends OmniscriptBaseMixin(LightningElement) {
    @api recordId;
    @track dataJson = {};

    @wire(CurrentPageReference)
    wireCurrentPageReference(currentPageReference) {
        if (currentPageReference) {
         const data={
            "ContextId":currentPageReference.attributes.recordId,
        }
        this.dataJson = data;
        }
    }
}
By using wire adapter and CurrentPageReference we can get the current page recordId and pass the recordId as
ContexId because in DataRaptor we are using ContextId as the Data Source.
6. Now open xml file and copy below code.
7. From setup -> App -> open the app according to your requirement and add the LWC in Utility Items.
Output:


 


 

Comments

Popular posts from this blog

Vlocity Facts #01 | OmniStudio DataRaptors

Vlocity Facts #34 || Getting the details from the URL in a FlexCard and an Omniscript

Vlocity Facts #44 || Communication between Omniscript and Flexcard [Pub/Sub]