0

I have a button on custom object which is when clicked should update the status of the record to "Awaiting Approval" Below is the lightning Component

<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId">
    <aura:handler name="init" value="{!this}" action="{!c.handleInit}"/>
    <aura:attribute name="currentRR" type="Object"/>
    <aura:attribute name="recordError" type="String"/>
    <aura:attribute name="recordSuccess" type="String"/>
    <aura:attribute name="showButton" type="Boolean" default="false" />
    <force:recordData aura:id="RRLoader"
        recordId="{!v.recordId}"
        fields="Status__c,Approval_1_Date__c,Approval_2_Date__c, Approval_3_Date__c, Approval_4_Date__c,Submitted_Date__c"
      targetFields="{!v.currentRR}"
      targetError="{!v.recordError}"
      recordUpdated="{!c.recordUpdated}"
      mode="EDIT"
 />
<aura:if isTrue="{!v.showButton}">
    <lightning:button variant="brand" label="Reset Rejected Request" onclick="{! c.handleClick }" />
</aura:if>
</aura:component>

Below is the controller.js

({
    recordUpdated: function(component, event, helper){
        var eventParams = event.getParams();
        if(eventParams.changeType != "ERROR") {
            component.set('v.showButton', true);
        }
    },
    handleInit : function(component, event, helper) {
    },
    handleClick: function(component, event, helper) {
        var record = component.get('v.currentRR');
        console.log(record);
        if(record.Status__c == 'Rejected'){
            record.Approval_1_Date__c = null;
            record.Approval_2_Date__c = null;
            record.Approval_3_Date__c = null;
            record.Approval_4_Date__c = null;
            component.find("RRLoader").saveRecord($A.getCallback(function(saveResult) {
            if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "Success!",
                    "message": "Account was successfully reset.",
                    "type": "success"
                });
                toastEvent.fire();
            } else if (saveResult.state === "INCOMPLETE") {
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "Error",
                    "message": "Please try again.",
                    "type": "error"
                });
                toastEvent.fire();
            } else if (saveResult.state === "ERROR") {
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "Error",
                    "message": "This Account request was not reset. Please try again.",
                    "type": "error"
                });
                toastEvent.fire();
            } else {
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "Error",
                    "message": "This Account request was not reset. Please try again.",
                    "type": "error"
                });
                toastEvent.fire();
            }
        }));
        } else {
            component.set('v.recordError', 'This Account Request is not rejected and cannot be reset.');
            var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "Error",
                    "message": "This Account request was not reset. Please try again.",
                    "type": "error"
                });
                toastEvent.fire();
        }
    }
})

From the above page, when reset approval request, we have an toast message showing on page which says "success". Along with that, the record's status should be updated to "Awaiting approval". And when the status is updated to Awaiting approval, the record should be auto submitted for approval.

Can anyone suggest me on how to do so.

1 Answer 1

1

Looks like you just need to do two things. First, change the status:

record.Status__c = 'Awaiting Approval';
...
component.find('RRLoader')...

Next, you can build a Process to submit the record for approval once the status is changed to Awaiting Approval.

0

You must log in to answer this question.

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