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
Zeel ShethZeel Sheth 

lightning component event not fired or handled

hii everyone,

I have 2 aura component, one component containing one button to open another aura component. I am passing userid input value using the application event but I  get the value zipcodeslisttcontroller.js. 
pls correct me.

zip_code_get_params.cmp

<aura:component controller="ZipCodeList">
    <aura:registerEvent name="zipcodelloaded" type="c:zipcodelloaded"/>
    <aura:handler name="init" value="{!this}" action="{!c.onInit}" includefacets="true"/>
    <aura:attribute name="terr_name" type="String" default=""/>
    
    <aura:attribute name="user" type="ET_MOSI_Zip_Code_Territory_Mapping__c" default="{ sobjectType: 'ET_MOSI_Zip_Code_Territory_Mapping__c'}"/>
    <lightning:card title="Enter Parameter" iconName="standard:search">
        <div class="slds-form slds-p-around_x-small">
            <lightning:layout horizontalAlign="space" multipleRows="true">
                <lightning:layoutItem size="12"
                                      mediumDeviceSize="12"
                                      padding="around-small">
                    <lightning:input
                                     label="Territory Name"
                                     variant="label-hidden"
                                     value="{!v.terr_name}"
                                     placeholder="Enter Territory Name"
                                     /> 
                    
                </lightning:layoutItem>
                
            </lightning:layout>
            
            
            
        </div><!--onchange="{!c.onSearchTermChange}"-->
    </lightning:card>
    FSE Name:<force:inputfield
                               
                               aura:id="user_id"
                               value="{!v.user.Service_User__c}"
                               change = "{!c.UserChange}"
                               /> 
    
        <div class="slds-form slds-p-around_x-small">
            <lightning:layout horizontalAlign="space" multipleRows="true">
                <lightning:layoutItem size="12"
                                      
                                      mediumDeviceSize="11"
                                      padding="around-small">
                    
                </lightning:layoutItem>
                <lightning:layoutItem size="12"
                                      mediumDeviceSize="1"
                                      padding="around-small">
                    <lightning:button onclick="{!c.onInit}">Go</lightning:button>
                </lightning:layoutItem>
            </lightning:layout>
            
            
            
        </div><!--onchange="{!c.onSearchTermChange}"-->
    
</aura:component>

controller.js
({
    onInit: function( component, event, helper ) {
        // proactively search on component initialization
        var terr_name = component.get( "v.terr_name" );
        var user_id = component.get( "v.user.Service_User__c" );
        //alert(user_id);
        helper.handleSearch( component,event, terr_name,user_id );
    },
    
   })

hepler.js
({
    // code in the helper is reusable by both
    // the controller.js and helper.js files
    handleSearch: function( component,event, terr_name,user_id ) {
        var action = component.get( "c.searchList" );
        action.setParams({
            terr_name: terr_name
        });
        action.setCallback( this, function( response ) {
            var event = $A.get( "e.c:zipcodelloaded" );
            event.setParams({
                "list1": response.getReturnValue(),
                //"user_idd": component.get("v.user_id")
            });
            event.fire();
        });
        $A.enqueueAction( action );
        
         var userid = component.find("user_id").get("v.value");
        alert(userid);
        console.log("hey"+userid);
        var appEvent = component.getEvent("zipcodelloaded"); 
        appEvent.setParams({
            "user_idd":userid}); 
          
            appEvent.fire(); 
        //alert("hey"+appEvent.getParam("user_idd"));
        
    }
})

event
zipcodelloaded.evt
<aura:event type="APPLICATION">
    <aura:attribute name="list1" type="ET_MOSI_Zip_Code_Territory_Mapping__c[]"/>
    <aura:attribute  name="user_idd" type="id"/>
</aura:event>

zipcodelistt.cmp
<aura:component controller="UpdateUser1">
    <aura:handler name="" event="c:zipcodelloaded" action="{!c.onZipCodesLoaded}" />
    <lightning:navigation aura:id="navigation"/>
    <aura:attribute name="rows" type="Map[]"/>
    <aura:attribute name="cols" type="Map[]"/>
    <aura:attribute name="selectedRows" type="List"/>
    <aura:attribute name="selection" type="List" access="PRIVATE"/>
    <aura:attribute name="user_iid" type="string"/>
     <aura:attribute name="selectedZipCodes" type="List"/>
    <lightning:card title="Zip Code List" iconName="standard:account">
        <lightning:datatable
                             data="{!v.rows}"
                             columns="{!v.cols}"
                             keyField="Id"
                             hideCheckboxColumn="false"
                             showRowNumberColumn="true"
                             
                             
                             aura:id="list"
                              onrowselection="{! c.handleGroupChange }" />
    </lightning:card>
    <lightning:layout>
        <lightning:layoutItem size="12"
                              mediumDeviceSize="11"
                              padding="around-small">
            
        </lightning:layoutItem>
        <lightning:layoutItem size="12"
                              mediumDeviceSize="1"
                              padding="around-small">
           <lightning:Button onclick="{!c.update}" >Update</lightning:Button>
        </lightning:layoutItem>
        
    </lightning:layout>
</aura:component>

controller.js
({
    onZipCodesLoaded: function( component, event, helper ) {
        var cols = [
            {
                'label': 'Zip Code',
                'fieldName': 'Name',
                'type': 'url',
                'typeAttributes': {
                    'label':{
                        'fieldName': 'Name'
                    }                     
                }
            },            
            {
                'label': 'Service Territory',
                'fieldName': 'Service_Territory1__c',
                'type': 'text'
            },
            {
                'label': 'Service Region',
                'fieldName': 'Service_Region__c',
                'type': 'Text'
            },
            {
                'label': 'FSE',
                'fieldName': 'Service_User__c',
                'type': 'Text'
            },
            
            
        ];
            component.set( 'v.cols', cols );
            component.set( 'v.rows', event.getParam( 'list1' ) );
            
            var t = event.getParam('user_idd');
            alert('heyy'+t);
           
            component.set('v.user_iid',event.getParam("user_idd"));
            console.log(component.get('v.user_iid'));
            //alert(ze);  here I get undefined value
            },
            
           /* IstAccount.forEach(item => 
            item['AccontUrl']='/lightning/r/Account/'+item['Id']+'/view';
            );*/
            
            
            
            
            handleGroupChange: function (cmp, event) {
            var selectedRowss = event.getParam('selectedRows');
            
            // cmp.set('v.selection', value);
            var setRows = [];
                for ( var i = 0; i < selectedRowss.length; i++ ) {
                    
                    setRows.push(selectedRowss[i].Id);
                    
                }
                cmp.set('v.selectedZipCodes', setRows);
       // alert(setRows);
                
            },
  update: function( component, event, helper ) {
        // proactively search on component initialization
        var selectedrows1 = component.get( 'v.selectedZipCodes' );
      var user1 = component.get('v.user_iid');
       // alert(selectedrows1);
        helper.updateFields( component,event,helper, selectedrows1 ,user1);
    }, 
    
})

hepler.js
({
        updateFields: function(component, event, helper,selectedrows1,user1) {
       
        
        var action1 = component.get('c.Update2');
            
            
        action1.setParams({
            "recordid": selectedrows1,
            "user_id": user1
        });
            alert(selectedrows1);
        action1.setCallback(this, function(response) {
            
            var state = response.getState();
            alert(state);
            if (state === "SUCCESS") {
                console.log(state);
                $A.get('e.force:refreshView').fire();
            }
        });
        $A.enqueueAction(action1);
    },
    
    
})

and I want hyperlink on name field and when click on those it should redirect to record page 

thanks in advananced,
zeel

 
VinayVinay (Salesforce Developers) 
Hi Zeel,

Can you provide with narrow down scenerio?  Also can you check logs.

Thanks,