Determine whether the Lightning component is in Lightning Console Or Normal App And Adding Icon and label to Tab

<cmp>
<aura:component >
    <!-- Console Api Library -->
     <lightning:workspaceAPI aura:id="workspace" />
    <aura:attribute name="Isconsole" type="Boolean" default="false" />
    
   <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>

Javascript:-
({
	doInit : function(component, event, helper) {
        var workspaceAPI = component.find("workspace");
            workspaceAPI.isConsoleNavigation().then(function(response) {
              console.log('Isconsole'+response);
                component.set("v.Isconsole",response);
                if(response){
                     workspaceAPI.getFocusedTabInfo().then(function(response) {
                        var focusedTabId = response.tabId;
                        workspaceAPI.setTabLabel({
                            tabId: focusedTabId,
                            label: "Edit"
                        });
                        workspaceAPI.setTabIcon({
                                    tabId: focusedTabId,
                                    icon: "utility:edit",
                                    iconAlt: "Edit Tab"
                        });
                    })
                    .catch(function(error) {
                        console.log(error);
                    });
                }
             })
	}
})

Use the Isconsole attribute and Do the Navigations accordingly .

Resource: https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_methods_lightning.htm

Leave a Reply

avatar
  Subscribe  
Notify of