0

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);
    },

1 Answer 1

0

I think the syntax is wrong.

var orderEvent = $A.get("e.OrderIdEvent");

Just try Replacing above line in your tablecmp helper with

var orderEvent = $A.get("e.c:OrderIdEvent");

Let me know if this helps

1
  • I updated the syntax already and still show undefined in first round.
    – Ssp1145
    Commented Oct 16, 2020 at 9:52

You must log in to answer this question.

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