0

I have overriden new Account and Edit Account standard actions with some custom Lightning Components. On console navigation apps i want to close some tabs on Account save and then open a new tab to the record id just created. But this does not seem to work and i do not understand the reason why.

navigateTo: function(component, recId) {
        //First determine whether navigation is Console or Standard
        var workspaceAPI = component.find("workspace");
        workspaceAPI.isConsoleNavigation().then(function(response) {
            if (response) { //navigation is console
                //Open a new tab with the record
                workspaceAPI.openTab({
                    recordId: recId,
                    focus: true,
                    overrideNavRules: true
                }).catch(function(error) {
                    console.log('error' +error);
                });
                workspaceAPI.getAllTabInfo().then(function(response) {
                    console.log(response);
                    for (var i=0; i<=response.length; i++) {
                        if ((response[i].title == 'Loading...') || (response[i].title == 'New Account') || (response[i].title == 'Νέος πελάτης') || (response[i].title == 'Φόρτωση...')) {
                            console.log(response[i].title);
                            workspaceAPI.closeTab({tabId: response[i].tabId});
                        }
                    }
                })
                .catch(function(error) {
                    console.log(error);
                });
            } else { //Standard navigation
                var navEvt = $A.get("e.force:navigateToSObject");
                navEvt.setParams({
                    "recordId": recId
                });
                navEvt.fire();
                window.setTimeout(
                    $A.getCallback(function() {
                        $A.get('e.force:refreshView').fire();
                    }), 2000
                );
            }
        })
    },  

The issue is, new tab opens, the tabs i want to close get closed, but focus is not on the opened tab by my code. It is one tab left from the tab opened by my code. Any Ideas ?

1 Answer 1

2

I also had this issue. But by using workspaceApi.focusTab() method, I was able to achieve the opening new tab and closing the current one and focusing the new tab.

workspaceAPI.openTab({
    pageReference: {
        "type": "standard__recordPage",
        "attributes": {
            "recordId": oldCaseId,
            "actionName":"view"
        }
    },
    focus: true
}).then(function(newTabId){
    workspaceAPI.getEnclosingTabId()
    .then(function(enclosingTabId) {
        workspaceAPI.closeTab({tabId : enclosingTabId});
        workspaceAPI.focusTab(newTabId);
    });

});

Hope this helps you. Let me know if it works.

1
  • Sree Kalyan, thank you very much for your answer. I had already solved the issue, but your solution is more or less the same with the one i imlpemented. Thanks again! Commented Apr 30, 2020 at 18:47

You must log in to answer this question.

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