2

I'm working on a requirement where I want a button which will open a modal to create a new Task record in LWC. For this, I tried using NavigationMixin. But onclick 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.

6
  • Is it a quick action? Just to be sure – Christian Croce Nov 11 '19 at 10:59
  • @ChristianCroce, No. It's not a quick action. We have an LWC component, where we want a button to create a new task. – Hemant Keni Nov 11 '19 at 11:33
  • 1
    OK, i think that's the standard way of the action. if you want to avoid it, you need to create your own component – Christian Croce Nov 11 '19 at 11:41
  • Did you ever find a solution for this? – zaitsman Jun 10 '20 at 7:25
  • 1
    @zaitsman, No. I didn't find any standard solution for this. We have customized screens for Tasks. – Hemant Keni Jun 12 '20 at 9:29
3
this[NavigationMixin.Navigate]({
  type: 'standard__objectPage',
  attributes: {
      objectApiName: this.childObjectApiName,
      actionName: 'new'                
  },
  state : {
      count: '1',
      nooverride: '1',
      useRecordTypeCheck : '1',
      defaultFieldValues: inheritParentString,
      navigationLocation: 'RELATED_LIST'
  }
});

You can append navigationLocation: 'RELATED_LIST' to state, and it will prevent navigation away from the current page. For some reason, this is not in the documentation and took me hours of crying into my palms before I found it in the url when using the action from a standard related list.

0

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 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.