Context: Using a lightning web component, I am trying to navigate from the Account page to the Case (New) page/dialog and set the new Case subject dynamically upon arrival. I have managed to make the button navigation work, but not the population of the new Case. I thought the PageRef State would take care of this, but nothing gets populated.
Current Code (HTML):
<template>
<!-- Create TSS Case Button -->
<lightning-button variant="neutral" label="Add TSS Case - 4" title="Add TSS Case" onclick={AddTSSCase_Click} class="slds-m-left_x-small"></lightning-button>
</template>
Current Code (JS):
import { LightningElement, wire, track, api } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
import { getRecord } from 'lightning/uiRecordApi';
export default class CreateNewTSSCaseButton extends NavigationMixin(LightningElement) {
@api recordId;
@wire(getRecord, { recordId: '$recordId', fields: ['Account.Name'] })
WiredAccount({error, data}) {
if (data) {
this.record = data;
this.error = undefined;
}
else if (error) {
this.record = undefined;
this.error = error;
}
}
@api tabName;
@api label;
connectedCallback() {
// Opening
console.log("connectedCallback.Start");
// Navigate to Account Page
this.accountHomePageRef = {
type: 'standard__objectPage',
attributes: {
objectApiName: 'Case',
actionName: 'new'
},
state: {
// NOT GETTINGS SET?
"Subject":"My Subject"
}
};
// Closing
console.log("connectedCallback.Finish");
}
AddTSSCase_Click() {
// Opening
console.log("AddTSSCase_Click.Start");
// Perform navitation
this[NavigationMixin.Navigate](this.accountHomePageRef);
// MAYBE SET SOMETHING HERE?
console.log(this.record.fields.Name.value);
// Closing
console.log("AddTSSCase_Click.Finish");
}
}
(Questions in all caps as comments in the JS)