+ Start a Discussion
Jefferson FernandezJefferson Fernandez 

Aura workspace api how to close the Loading… subtab and focus the New object create subtab

I'm using lightning:isurladdressable to open a subtab, then in turn fire a createRecord event with default values populated. It opens 2 sub tab "Loading..." and the "New" tab. I want to close the "Loading..." and go back to "New". I can close the Loading tab but the focus goes to the first tabs that were opened and not the "New" tab that. I used the getAllTabInfo to possibly use the Id and focus to the New tab but its not there. Any ideas on how to go to the New after closing the Loading...


User-added imageUser-added image
 
({ doInit : function(component, event, helper) { var callback = function(response) { if (response) { helper.fireCreateEvent(component, event, response); helper.closeBlankSubtab(component, event, response); } } let pgState = component.get("v.pageReference").state; component.set("v.acctId", pgState.c__acctId); var params = { "acctId" : component.get("v.acctId") } helper.callServer(component, 'c.getDirectAcr', params, callback, helper); }, }
fireCreateEvent : function(component, event, acr) {
        var createEvent = $A.get("e.force:createRecord");
            createEvent.setParams({
            "entityApiName" : "AccountContactRelation",
            "defaultFieldValues" : {
                "ContactId" : acr.ContactId,
                "JobTitle__c" : acr.JobTitle__c,
                "Language__c" : acr.Language__c,
                "CommunicationMethod__c" : acr.CommunicationMethod__c,
                "Function__c" : acr.Function__c,
                "Telephone__c" : acr.Telephone__c,
                "MobilePhone__c" : acr.MobilePhone__c,
                "Fax__c" : acr.Fax__c,
                "Email__c" : acr.Email__c,
                "SafetyResponsible__c" : acr.SafetyResponsible__c,
                "EnvironmentResponsible__c" : acr.EnvironmentResponsible__c,
                "PricingResponsible__c" : acr.PricingResponsible__c,
                "QuotationRepairResponsible__c" : acr.QuotationRepairResponsible__c,
                "FMMainContact__c" : acr.FMMainContact__c,
                "FleetExchange__c" : acr.FleetExchange__c,
                "ONTrack__c" : acr.ONTrack__c,
                "IsDirect" : false
            }
        });
        createEvent.fire();
    },

    closeBlankSubtab: function(component, event, response) {
      let self = this;
      var workspaceAPI = component.find("workspace");
      workspaceAPI
        .getAllTabInfo()
        .then(function(tabInfos) {
          let tabIdToClose;
          for (let i = 0; i < tabInfos.length; i++) {
            for (let j = 0; j < tabInfos[i].subtabs.length; j++) {
              if (tabInfos[i].subtabs[j].title === "Loading...") {
                tabIdToClose = tabInfos[i].subtabs[j].tabId;
              }
            }
          }
          workspaceAPI.closeTab({tabId: tabIdToClose})
            .then(function(result) {  
            });
      })
      .catch(function(error) {
      });
    },

​​​​​​​