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
shubham soitkar 6shubham soitkar 6 

Lightning buttton onclick not executing, could someone please help me

controller:-

({
    doInit : function(component, event, helper) {
           // create a one-time use instance of the serverEcho action
        // in the server-side controller
        var action = component.get("c.getcontact");
        action.setParams({ accountId : component.get('v.recordId'), });
 
        // Create a callback that is executed after 
        // the server-side action returns
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                // Alert the user with the value returned 
                // from the server
                component.set("v.contactname",response.getReturnValue());
                 console.log(response.getReturnValue());
                // You would typically fire a event here to trigger 
                // client-side notification that the server-side 
                // action is complete
            }
            else if (state === "INCOMPLETE") {
                // do something
            }
            else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                                 errors[0].message);
                    }
                } else {
                    console.log("Unknown error");
                }
            }
        });
 
        // optionally set storable, abortable, background flag here
 
        // A client-side action could cause multiple events, 
        // which could trigger other events and 
        // other server-side action calls.
        // $A.enqueueAction adds the server-side action to the queue.
        $A.enqueueAction(action);
    },
    
     doButton : function(component, event, helper) {
        var eventSource = event.getSource();
        var id = eventSource.get(v.name);
        alert(id); 
    }
});

Aura Component:

<aura:component controller="contactclass" implements="flexipage:availableForAllPageTypes,force:hasRecordId">
    
    <aura:attribute name="contactname" type="Contact[]" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    
    {!v.recordId}
    <div class="slds-grid slds-wrap">
        <aura:iteration items="{!v.contactname}" var="item" >
              <div class="slds-col slds-size_1-of-3">
                  <div class="slds-p-around_x-small">
                <lightning:card footer="Business Card" title="Cognizant" variant="Narrow"  iconName="standard:employee_asset">
                    <aura:set attribute="actions">
                    
                        <lightning:button variant="brand" name="values"  label="More" title="Brand action" onclick="{!c.doButton }" />                  
                    </aura:set>
                        <p class="slds-p-horizontal_small">
                             {!item.FirstName} &nbsp; {!item.LastName}<br />
                            </p>
                   </lightning:card>
              </div>        
            </div>             
        </aura:iteration>
     
    </div>    
    
</aura:component>

contact class:-
Best Answer chosen by shubham soitkar 6
Ashvin JAshvin J
Hi Shubham,

Try below line 

var id = eventSource.get("v.name"); 

Thanks

All Answers

ravi soniravi soni
hi shubham,
replace following method. you forgot to put v.name into string.
It must be in 'v.name'.
 
doButton : function(component, event, helper) {
        var eventSource = event.getSource();
        var id = eventSource.get('v.name');
        alert(id); 
    }
let me know if it helps you and don't forget to marking it as best.
Thank you
 
Ashvin JAshvin J
Hi Shubham,

Try below line 

var id = eventSource.get("v.name"); 

Thanks
This was selected as the best answer
shubham soitkar 6shubham soitkar 6
Thanks it's worked for me!