I have table of records that I can click on. When click, it must fire the event then open new console tab but event attribute show undefined when tab is open for first time. My lightning event attribute is working fine when particular tab is opened.
OrderIdEvent
<aura:event type="APPLICATION" description="" >
<aura:attribute name = "orderId" type="String" default=""/>
</aura:event>
TableCmp.cmp
<aura:registerEvent name="orderEvent" type="c:OrderIdEvent"/>
TableCmp.js
navigateToURL: function (component, event, helper) {
var arrList = event.target.value;
var result = arrList.split("@");
var selectedAccountId = result[0];
console.log('Selected Account Id = ', selectedAccountId);
component.set('v.accountId', selectedAccountId);
//
const orderEvtparam = {'orderId':'12345'};
helper.fireOrderIdEvent('OrderIdEvent',orderEvtparam);
var url = '/lightning/r/Account/'+selectedAccountId+'/view';
var workspaceAPI = component.find("workspace");
workspaceAPI.getFocusedTabInfo().then(function (response) {
workspaceAPI.openTab({
url: url,
focus: true
}).then((response) => {
workspaceAPI.refreshTab({
tabId: response,
includeAllSubtabs: true
});
});
}).catch(function (error) {
console.log(error);
});
},
Tablecmp.helper
fireOrderIdEvent : function(evtName,params){
try{
var orderEvent = $A.get("e.c:OrderIdEvent");
orderEvent.setParams(params);
orderEvent.fire();
console.log('fire!');
}catch(err){
console.log(err);
}
},
SecondCmp.cmp
<aura:handler event="c:OrderIdEvent" action="{!c.handleEvent}" />
SecondCmp.js
handleEvent :function(component,event,helper){
var orId = event.getParam("orderId");
console.log('orId event = ' + orId);
},