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
Raju Chi 5Raju Chi 5 

update status filed using lightning component button

Hi 

I have created lightning:recordEditform and recordform lightning component, and inside component i have Approve button.

When click on approve button back end i need to update status filed as Approved and render to Edit form to View Form.
<lightning:recordEditForm recordId="{!v.RwaIDFromVfPage}" 
                              objectApiName="Order" 
                              aura:id="recordHandler"
                               onload="{!c.handleLoad}"
                              onsuccess="{!c.handleSuccess}"
                              onsubmit="{!c.handleSubmit}">
         
        <lightning:messages />
        <div class="slds-wrap slds-text-align_center">
            <lightning:button disabled="{!v.disabled}"  type="submit" name="save" label="Save" />
             <lightning:button type="button" name="Approve" label="Approve" onclick="{!c.approveMethod}" />
            <!-- <lightning:button type="button" name="Reassign" label="Reassign" />   -->         
            <lightning:button type="button" variant="neutral" label="Cancel" title="Cancel" onclick="{!c.handleCancel}" />
            
        </div>  

 approveMethod: function (component, event, helper) {
       // var action= component.get("c.Form");
        console.log("abcd");
    /*  event.preventDefault(); //Prevent default submit
        var eventFields = event.getParam("fields"); //get the fields\
        console.log("qwefrty"+eventFields);
        eventFields["Status__c"] = 'Approved'; //Add Description field Value
        console.log('hiii'+ eventFields["Status__c"]);
        component.find('RWAForm').submit(eventFields); */
        
      
         var btnClicked = event.getSource();
        btnClicked.set("v.disabled",true);
        $A.enqueueAction(action);
        
    },

Please let me know how to handle this.
ravi soniravi soni
Hi Raju,
try this dummy component in your org. I Hope it will able to fulfill your requirment.
<aura:component implements="flexipage:availableForAllPageTypes,
                            flexipage:availableForRecordHome,
                            force:hasRecordId" access="global" controller="updateOrder">
    <aura:attribute name="disabled" type="boolean" default="false"/>
    <aura:attribute name="statusValue" type="string" />
        <aura:attribute name="orderRecordId" type="string" default="8015g000000PNXEAA4"/>
       <aura:if isTrue="{!v.disabled}">
   
   
    <aura:set attribute="else">
         <lightning:recordEditForm recordId="{!v.orderRecordId}" 
                              objectApiName="Order" 
                              aura:id="recordHandler"
                               onload="{!c.handleLoad}"
                              onsuccess="{!c.handleSuccess}"
                              onsubmit="{!c.handleSubmit}">
          
        <lightning:messages />
          <lightning:outputField fieldName="AccountId" />
        <lightning:outputField fieldName="ContractId" />
        <lightning:inputField fieldName="Name" />
        <lightning:inputField fieldName="Status__c" value="{!v.statusValue}" aura:id="statusFld"/>
        
        <div class="slds-wrap slds-text-align_center">
            <lightning:button disabled="{!v.disabled}"  type="submit" name="save" label="Save" />
             <lightning:button type="button" name="Approve" label="Approve" onclick="{!c.approveMethod}" />
            <!-- <lightning:button type="button" name="Reassign" label="Reassign" />   -->         
            <lightning:button type="button" variant="neutral" label="Cancel" title="Cancel" onclick="{!c.handleCancel}" />
            
        </div>  
    </lightning:recordEditForm>
           </aura:set>
        <lightning:recordViewForm recordId="{!v.orderRecordId}"
                                  objectApiName="Order">
        <div class="slds-box">
         <lightning:outputField fieldName="AccountId" />
        <lightning:outputField fieldName="ContractId" />
        <lightning:outputField fieldName="Name" />
        <lightning:outputField fieldName="Status__c" value="{!v.statusValue}" aura:id="statusFld"/>
        
        </div>
    </lightning:recordViewForm>
    </aura:if>
</aura:component>
 
({
	approveMethod: function (component, event, helper) {
        component.set('v.statusValue','Approved');
       
       
        var action = component.get("c.updateStatus");
        action.setParams({ orderId : component.get("v.orderRecordId") });
        action.setCallback(this, function(response) {
            var state = response.getState();
            alert(state);
            if (state === "SUCCESS") {
                alert("From server: " + response.getReturnValue());
            }
            else if (state === "INCOMPLETE") {
                // do something
            }
            else if (state === "ERROR") {
                var errors = response.getError();
                console.log(JSON.stringify(errors));
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                                 errors[0].message);
                    }
                } else {
                    console.log("Unknown error");
                }
            }
        });
 
        $A.enqueueAction(action);
        component.set("v.disabled",true);
        
    },
    handleLoad: function (component, event, helper) {
        console.log('it is loading');
    },
      handleSubmit: function (component, event, helper) {
        console.log('handleSubmit');
        },
   handleSuccess: function (component, event, helper) {
        console.log('handleSuccess');
    }
    
    

})
 
public class updateOrder {
@AuraEnabled
    public static Order updateStatus(string orderId){
        
        Order oOrder = [SELECT Id,Name,Status From Order WHERE Id =:orderId ];
            oOrder.Status__c = 'Approved';
         update oOrder;
        return oOrder;
        
    }
}

In my org It is working fine.
let me know what is your experance about this answer And if it helps you, marking it as best.
Thank You
ravi soniravi soni
Hi Raju,
you will have to change recordId and made some changes according your requirment.
Thank you
Raju Chi 5Raju Chi 5
Hi Soni,

Thanks fro the response. I will try this and let you know the same.
Regards,
Raju