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
louisa barrett 7louisa barrett 7 

Get ID of lightning:button that was used in the onsuccess attribute on a Lightning:recordEditForm

Hi,

I was wondering if there was a way to get the ID of the button that was clicked on a recordEditForm within the onsuccess method.
I have tried 
console.log(event.getSource().getLocalId());
but that just returns the ID of the recordEditForm, not the button that was clicked.
The reason I need this is I want to display two buttons, one that simply updates the case and the other which updates the case and closes the workspace tab

This is my component
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">
    <lightning:workspaceAPI aura:id="workspace"/>
    <aura:attribute name="showSpinner" type="Boolean" default="true"/>
    <aura:if isTrue="{!v.showSpinner}">
        <lightning:spinner />
    </aura:if>
    <div class="slds-box slds-theme_default">
        <div class="slds-text-title_bold">Updates the status to closed and closes the primary tab</div>
        <lightning:recordEditForm aura:id="recordEditor"
                                  onload="{!c.handleLoad}"
                                  onsubmit="{!c.handleSubmit}"
                                  onsuccess="{!c.handleSuccess}"
                                  recordId = "{!v.recordId}"
                                  objectApiName="Case">
            <lightning:messages />
            <lightning:inputField fieldName="Fault_Category__c" disabled="true" />
            <lightning:inputField fieldName="Fault_Type__c" />
            <lightning:inputField fieldName="Solution__c" />
            <lightning:inputField fieldName="Solution_Details__c" />
            <div class="slds-m-top_medium">
                <lightning:button aura:id="button1" value="value1" variant="brand" type="submit" name="save" label="Close Case and Tab" />
                <lightning:button aura:id="button2" value="value2" variant="brand" type="submit" name="save2" label="Close Case" />
            </div>
        </lightning:recordEditForm>
    </div> 
</aura:component>
This is the controller
({
    handleLoad : function(component, event, helper) {
        console.log('handle handleLoad');
        component.set("v.showSpinner", false);
    },
    
    handleSubmit : function(component, event, helper) {
        event.preventDefault(); // Prevent default submit
        var fields = event.getParam("fields");
        fields["Status"] = 'Hold';        
        component.find('recordEditor').submit(fields); // Submit form
        console.log('handle handleSubmit');
    },
    
    handleSuccess : function(component, event, helper) {
        console.log('record updated successfully');
        //The below is returning the id of the Lighting:recordEditForm 
        console.log(event.getSource().getLocalId());
        component.set("v.showSpinner", false);
        // Success! Prepare a toast UI message
        var resultsToast = $A.get("e.force:showToast");
        resultsToast.setParams({
            "title": "Case Saved",
            "message": "The case has been closed"
        });
        resultsToast.fire();
        
        //Below should only fire if a specific lighting button was pressed
        var workspaceAPI = component.find("workspace");
        console.log('closing tab');
        workspaceAPI.getFocusedTabInfo().then(function(response) {
            var focusedTabId = response.tabId;
            workspaceAPI.closeTab({tabId: focusedTabId});
        })
        .catch(function(error) {
            console.log(error);
        });
    }
})
I have highlighted the commented code in bold in the controller where I need to reference the button that was clicked

Any help would be much appreciated