You need to sign in to do that
Don't have an account?
Andegosu
LWC: Chain javascript method after NavigationMixin
I have a datatable with a new button that uses the NavigationMixin.Navigate functionality in LWC.
After the record is created it default navigates to the record, I had to add "navigationLocation: 'RELATED_LIST'" to the state to make it stay on the original record page where the component is placed.
However, after the dialoge is done and new record has been created, it stops running. I want to refresh the datatable to display the new record but I can't run any code after NavigationMixin.
Is there anyway to solve this?
Code run when clicking new:
import { NavigationMixin, CurrentPageReference } from 'lightning/navigation';
After the record is created it default navigates to the record, I had to add "navigationLocation: 'RELATED_LIST'" to the state to make it stay on the original record page where the component is placed.
However, after the dialoge is done and new record has been created, it stops running. I want to refresh the datatable to display the new record but I can't run any code after NavigationMixin.
Is there anyway to solve this?
Code run when clicking new:
createNew() { let defaultFieldValues = ''; this.loading = true; if(this.parentFieldName !== null) { defaultFieldValues = this.parentFieldName +"="+this.recordId; } this[NavigationMixin.Navigate]({ type: 'standard__objectPage', attributes: { objectApiName: this.objectName, actionName: 'new' }, state : { nooverride: '1', defaultFieldValues: defaultFieldValues, navigationLocation: 'RELATED_LIST', recordTypeId: this.recordTypeId } }).then(result => { console.log(result); return refreshApex(this.wiredResult); }).catch(error => { console.log(error); }); }
So line 20: ".then(result => {" is invalid.
I would suggest using a modal window containing a lightning-record-edit-form to create the record, then use onsuccess event to call refreshApex.
You may refer this URL for how to implement lighting-record-edit-form.
https://developer.salesforce.com/docs/component-library/bundle/lightning-record-edit-form/documentation