0

I have an Omniscript with a custom picklist field (Picklist value populated from the Apex method), which is working fine. Within the same step as this picklist field, I have an LWC and I am sending the selected picklist value to this LWC.

In the LWC I can see the passed value from omniscript using omniJsonData, however when the picklist value is changed in OS, the LWC is not getting refreshed with the new value. I mean LWC does not seem to be reactive to the value change in the Omniscript within the same step.

When I inspect the page in browser, I see the connectedcallback and renderedCallback is fired initially and then even if the picklist value is changed in the OS, it does not trigger a re-rendering of LWC.

Any idea to make the omniscript picklist value reactive and refresh the LWC accordingly.

Omniscript: enter image description here

LWC Code: enter image description here

1 Answer 1

-1

@track osData captures the omniJsonData reference ONCE at initialization When you change the form dropdown in Omniscript, it updates this.omniJsonData But this.osData still points to the old object reference Your getPortalUrlFromApex() uses stale data > No refresh!

3 lines to change

Replace your tracked property with a GETTER:

Original (WRONG): @track osData = this.omniJsonData; // WRONG Fixed (RIGHT): get osData() { //
return this.omniJsonData; } That's it! Now when Omniscript changes the value:

Omniscript updates this.omniJsonData LWC's getter always returns the current value Your getPortalUrlFromApex() gets fresh data

Here is the corrected code fo ryour component

import { LightningElement, api, track } from 'lwc'; import { OmniscriptBaseMixin } from "omnistudio/omniscriptBaseMixin"; import getPortalUrlFromApex from '@salesforce/apex/MNRF_NewPermitComponentCTRL.getPortalUrlFromApex'

export default class MnrfOSStartSubHelpUrl extends OmniscriptBaseMixin(LightningElement) {

@api record;
portalUrl;
portalTitle;
@track aggFormId;

//  FIX: Replace @track osData with getter
get osData() {
    return this.omniJsonData || {};
}

connectedCallback() {
    console.log('Inside MnrfOSStartSubHelpUrl: connectedCallback - record:', this.record);
    console.log('Inside MnrfOSStartSubHelpUrl: connectedCallback - omniJsonData:', JSON.stringify(this.omniJsonData));
    
    this.aggFormId = this.osData.FormSelection?.AggForm;
    console.log('Inside MnrfOSStartSubHelpUrl: connectedCallback - aggFormId:', this.aggFormId);
    this.getPortalUrlFromApex();
}

renderedCallback() {
    console.log('Inside MnrfOSStartSubHelpUrl: renderedCallback - record:', this.record);
    console.log('Inside MnrfOSStartSubHelpUrl: renderedCallback - omniJsonData:', JSON.stringify(this.omniJsonData));
    
    //  Check if form selection changed
    const newAggFormId = this.osData.FormSelection?.AggForm;
    if (newAggFormId !== this.aggFormId) {
        console.log('FormSelection changed from', this.aggFormId, 'to', newAggFormId);
        this.aggFormId = newAggFormId;
        this.getPortalUrlFromApex();  // ← Re-fetch portal URL
    }
}

getPortalUrlFromApex() {
    console.log('Inside MnrfOSStartSubHelpUrl - getPortalUrlFromApex - record:', this.record);
    
    getPortalUrlFromApex({ templateId: this.record })
        .then(result => {
            console.log('Inside MnrfOSStartSubHelpUrl - getPortalUrlFromApex:result:', result);
            let resString = result.split(";");
            this.portalUrl = resString[0];
            this.portalTitle = resString[1];
            console.log('Inside MnrfOSStartSubHelpUrl - Portal URL retrieved:', this.portalUrl);
        })
        .catch(error => {
            console.error('Error in getPortalUrlFromApex:', error);
        });
}

} ⚡ OPTIONAL: ADD POLLING FOR GUARANTEED UPDATES If the above fix alone doesn't work, add this polling mechanism:

connectedCallback() { // ... existing code ...

//  Add polling as fallback
this._refreshInterval = setInterval(() => {
    const newFormId = this.osData?.FormSelection?.AggForm;
    if (newFormId && newFormId !== this._lastFormId) {
        this._lastFormId = newFormId;
        this.aggFormId = newFormId;
        this.getPortalUrlFromApex();
    }
}, 500);  // Check every 500ms

}

disconnectedCallback() { // Clean up polling if (this._refreshInterval) { clearInterval(this._refreshInterval); } } Omni Configuraiton (Right side panel)
Make sure your LWC property binding in Omniscript is correct:

Property Name: record Property Source: ={FormSelection.AggForm}

OR if you need the entire FormSelection object:

Property Name: record Property Source: ={FormSelection}

Important: Use ={} syntax, not % syntax!

1
  • If you're using an AI tool to make answers, and this shows several such hallmarks of that, know that we do not allow AI-generated answers here. Commented Oct 29 at 2:35

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.