1

I am having one scenario where i need to pass record id from LWC to Omniscript. I got the record Id in the track variable, but i am strugling to assign as the below at the place of abc.

<c-test-for-jate prefill='\{"ContextId":"abc","otherParam":"test"}' layout="lightning"></c-test-for-jate>

JS
@track rIdFromAccount;
    @api set recordId(value) {
        this._recordId = value;
        this.rIdFromAccount = value;
   }
    get recordId() {
        return this._recordId;
    }

Trying below to set the recordId dynamically.

 <c-test-for-jate prefill='\{"ContextId":"{rIdFromAccount}","otherParam":"test"}' layout="lightning"></c-test-for-jate>

Throwing the below error :Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'error')

When i am hardcoding the id salesforce is working as expected.

2 Answers 2

1

To dynamically set the record ID in the prefill attribute, you should use JavaScript's string concatenation instead of directly embedding the variable in the template string.

Modify the code as follows:

JS:

@track rIdFromAccount;
@api set recordId(value) {
    this._recordId = value;
    this.rIdFromAccount = value;
}
get recordId() {
    return this._recordId;
}

HTML:

<c-test-for-jate prefill={getPrefillData} layout="lightning"></c-test-for-jate>

Now, in your JS file, create a method named getPrefillData that returns the prefill data as a string:

JS:

get getPrefillData() {
    return JSON.stringify({ ContextId: this.rIdFromAccount, otherParam: "test" });
}

In this updated code, we use the getPrefillData method to dynamically generate the prefill attribute value, which includes the record ID obtained from the rIdFromAccount variable.

Hope this helps !

0

I was also facing the same issue in one of the requirements. You need to set the record ID in the below format to pass it from LWC to embedded Omniscript.

<c-test-for-jate record-id={recordId} layout="lightning"</c-test-for-jate

where recordId is the id of the record which you want to pass to the omniscript.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .