function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nilesh DetheNilesh Dethe 

How to avoid navigation to newly created record using NavigationMix?

Hi All,
 
I'm working on a requirement where I want a button that will open a modal to create a new Task record in LWC. For this, I tried using NavigationMixin. But on click of Save in the modal, it redirects to the newly created record page instead of closing the modal. Is there any way to skip the navigation to the newly created record and close the modal only.
Below is the code of NavigationMixin that I'm using:
this[NavigationMixin.Navigate]({ type: 'standard__objectPage', attributes: { objectApiName: 'Task', actionName: 'new' } });
 
Thanks in advance.
 
#LightningFramework #lightningwebcomponents  #LWC  #Navigationmixin
About MeAbout Me
Hi Nilesh, did you happen to solve or find any workaround for this one? thanks.
#LWC
Nikhil Sharma 219Nikhil Sharma 219
You can use aura component for achieving this. First, you have to send the call to aura component from your lwc component, use this link - https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.events_sending_to_aura_components

In lightning aura component you have to simply use this code in the handler onclick action method for achieving the scenario :
 
var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({ "entityApiName": "Task", "defaultFieldValues": { 'WhatId':filters },
 "navigationLocation": "LOOKUP",
 "panelOnDestroyCallback": function(event) { $A.get("e.force:closeQuickAction").fire();
 // window.location.href = window.history.back(); } });
 createRecordEvent.fire(); }

Hope this helps
RahulJoshi31RahulJoshi31
Hi Nilesh,
Please try this code

this[NavigationMixin.Navigate]({
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'Task',
                actionName: 'new'
            },
            state : {
                defaultFieldValues : defaultValue,
                navigationLocation: 'RELATED_LIST'
            }
})
karan singhalkaran singhal
Thanks Rahul, it worked for me
RahulJoshi31RahulJoshi31
Please mark it as the best answer.