+ Start a Discussion
louisa barrett 7louisa barrett 7 

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


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 
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 />
    <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"
                                  recordId = "{!v.recordId}"
            <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" />
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 
        component.set("v.showSpinner", false);
        // Success! Prepare a toast UI message
        var resultsToast = $A.get("e.force:showToast");
            "title": "Case Saved",
            "message": "The case has been closed"
        //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) {
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