0

I have lightning:recordeditform with two buttons.

One of them is used to submit the form and save the sObject record based on the values entered in the inputfield of recordeditform. Second button needs to submit the form and then use the updated record for further processing.

<lightning:recordEditForm density="compact" aura:id="myform" recordId="{!v.recordId}" objectApiName="customObject__c" onsubmit="{!c.handleSubmit}" onload="{!c.handleLoad}" onsuccess="{!c.handleSuccess}" onerror="{!c.handleError}"> 
<lightning:button class="slds-button slds-button_brand" variant="brand" name="Save"  type="submit" label="Save" value="Save" />
<lightning:button class="slds-button slds-button_brand" variant="brand" name="Submit and then Process"  type="button" value="Submit To Payable Invoice Process" label="Submit To Payable Invoice Process" onclick="{!c.handleSubmitProcess}" />
</lightning:recordEditForm>

However, when the second button is clicked it saves record however it still picks the old value of sobject from database instead of the one just saved.

handleSubmit: function(component, event, helper) {
    console.log('handleSubmit');
    event.preventDefault(); // stop form submission
    component.find("myform").submit();
},
handleSubmitProcess: function(component, event, helper) {
    console.log('handleSubmitProcess');
    component.find("myform").submit();
    helper.submitProcess(component,event);
},

Anyway I can fix this? Thank you.

1 Answer 1

1

You need to wait for the database to process the record, which won't happen until some time later. Use the onSuccess handler for that purpose.

handleSubmitProcess: function(component, event, helper) {
    console.log('handleSubmitProcess');
    component.find("myform").submit();
    component.set("v.shouldSubmit", true);
},
handleSuccess: function(component, event, helper) {
    if(component.get("v.shouldSubmit")) {
        helper.submitProcess(component,event);
    }
},

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .