[SalesForce] component.find(“Name”).get(“v.value”); is not working

i am encountering error with below

Var req_val= cmp.find("required").get("v.value");

earlier it was working fine, now it is not working getting

error

Uncaught Action failed: c$my_comp$controller$closeTask [TypeError: Cannot read property 'get' of undefined] 

i am calling this function from Event

closeTask:function(cmp,event,helper){
console.log(cmp.find('required').get('v.value'));// here is the error

var eventId = event.getParam("recordId");

Event is registered in child and handling in parent. it consist of recordId.

required attribute is in parent. cant we get this attribute value in parent am getting as undefined.

please suggest.

Best Answer

create an aura:Attribute in your event, which you should pass while invoking the event

Aura attribute in event -

<aura:attribute name="sObjectId" type="Id" required="true" description="The Id of the selected SObject." />

While invoking event - var updateEvent = cmp.getEvent("eventName");

// Populate the event with the selected Object Id
updateEvent.setParams({
    "sObjectId" : value
}); 

In the event handler's action write following -

// Get the Id from the Event
var accountId = event.getParam("sObjectId");

Hope this helps :)