function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Valentin F.Valentin F. 

Getting error while trying to pass informations with application event

Hello everybody,
I'm creating an app with 3 different components.
I already have an application event to pass results of my queries in my component 1 to components 2 & 3.
I'd like to pass informations from component 2 to component 1 (the one binded to apex controller), do a soql query with these informations and sent the results in the first event.
The problem is that my second event is already fired when I try to select it and set it parameters.

Here is my code : 
Component2.cmp

<aura:registerEvent name="Event2" type="c:Event2"/>
Component2Helper.js

var object1 = object;
var event = $A.get("e.c:Event2");
event.setParams({"object1": object1});
event.fire();
Event2.evt

<aura:event type="APPLICATION">
    <aura:attribute name="object1" type="Object"/>
</aura:event>
And here is the error I get :
User-added imageThank you for your help and your answers !


 
Best Answer chosen by Valentin F.
Valentin F.Valentin F.
The problem was that an application event was already fired. 
I needed to create a component event. When this component event was fired, it called my other application event and passed it data. The application event fired too and pass data to my other component.

EventCmp.evt
<aura:event type="COMPONENT">
    <aura:attribute name="object1" type="Object"/>
</aura:event>
Event2.evt
<aura:event type="APPLICATION">
    <aura:attribute name="object1" type="Object"/>
</aura:event>
Component2.cmp
<aura:registerEvent name="eventCmp" type="EventCmp"/>
<aura:registerEvent name="appEvent" type="c:Event2"/>

<aura:handler name="eventCmp" event="c:EventCmp" action="{!c.onCompEvtCalled}"/>
Component2Controller.js
onCompEvtCalled: function(component, event, helper) {
    helper.passObject1ToApp(component, event, helper);
}
Component2Helper.js
var object1 = object;
var event = component.getEvent("eventCmp");
event.setParams({"object1":object1});
event.fire();
passObject1ToApp: function(component, event, helper) {
     var object1 = event.getParam("object1");
     var appEvent = $A.get("e.c:Event2");
     appEvent.setParams({"object1":object1});
     appEvent.fire();
}