3

Using the <lightning:workspaceapi> tag and calling the same reuseable component twice (once for edit and once for view) does not seem to let me open the edit page modal and open a new tab for viewing all at once. Instead, the edit modal gets removed as the view tab is created. Since the edit page is a standard record page type, I can't seem to get events from it.

Tab component basic code:

var workspaceAPI = component.find("workspace");

workspaceAPI.openTab({

pageReference: {    
       "type": "standard__recordPage",
       "attributes": {
           "recordId": component.get("v.thisRecordId"),
           "objectApiName": component.get("v.thisObj"),
           "actionName": component.get("v.thisAction")
       }
}
5
  • So you want to open the record in a tab, with the record page on edit mode, instead of a modal with the record info? Jun 11, 2019 at 13:59
  • Interestingly, the pageReference with "edit" as the actionName pops the modal rather than opening a tab. I like that. I just want the underlying tab to be a view of the same record. If I don't put the focus on the view tab, it doesn't open and users have to click on it after the edit. If I put focus on both, the edit modal gets trashed as the view tab is created since they are basically simultaneous.
    – snugsfbay
    Jun 11, 2019 at 14:02
  • Did you try to fire an openTab and then, after the promise resolves, fire another one but with the parameters specifying that it is the edit page instead of the record page? In theory that should open the record, and then open the edit modal. After the user saves it, it should display the record previously opened. Jun 11, 2019 at 19:09
  • Thanks, I am executing openTab as in example code but Parent component is not able to 'hear' the tabFocus event. Is there a better way to determine when the promise resolves?
    – snugsfbay
    Jun 11, 2019 at 20:18
  • Well, the promise returns the Id of the opened tab when resolved. There's no event for that, I believe. You need to call the "open on edit mode" when the promise is resolved, basically (again: theoretically, since I didn't test this myself yet). Jun 12, 2019 at 14:16

1 Answer 1

1

You'll have to combine the usage of the workspace API and the navigation API to achieve the behavior you want:

var workspaceApi = component.find('workspace')
var navigatorApi = component.find('navigator')

workspaceApi.openTab({
    recordId: '0015400000EFDivAAH',
    focus: true
}).then(function() {
    navigatorApi.navigate({
        type: 'standard__recordPage',
        attributes: {
            recordId: '0015400000EFDivAAH',
            actionName: 'edit'
        }
    })
})

This will make the application navigate to the record's detail page, and when that's done it will open the edit modal. After the user edits (or not) the record, what they will see in the background of the closed modal will be the record's detail page.

8
  • Is that using "lightning:navigationItemAPI" or using "lightning:navigation" ?
    – snugsfbay
    Jun 12, 2019 at 17:47
  • 1
    Using lightning:navigation. Jun 12, 2019 at 18:04
  • That's not popping open the edit modal for me, and I see you don't pass a type or action to the first tab. Do you think that's making a difference in the behavior you saw when you tried this code?
    – snugsfbay
    Jun 12, 2019 at 23:22
  • 1
    I honestly don’t know what could be wrong. Can you edit your original post with the updated code? It would help if you also provided some context for this feature of yours. Is it supposed to work when the user clicks on a button, for example? Jun 12, 2019 at 23:40
  • 1
    I had fired a force:closeQuickAction. It apparently closed the edit modal rather than the QA message modal, which goes away with the openTab as it should and doesn't need the close event. Getting rid of that event got your solution working for me. Thanks again for all the help.
    – snugsfbay
    Jun 13, 2019 at 14:24

You must log in to answer this question.

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