You need to sign in to do that
Don't have an account?
kohon
link Custom Approve/reject page and custom approval history
Hi All,
I have a custom Approve/Reject page and custom approval history.
How can I link both , like how to make it to go to the next approval step once it is approved/rejected.What am I doing wrong .pls let me know.
Here's the code.
JS:
approveall: function(component, event, helper) {
var allRecords = component.get("v.listOfAllAccounts");
var recordId = component.get("v.recordId");
var selectedRecords = [];
for (var i = 0; i < allRecords.length; i++) {
if(allRecords[i].isChecked ){
selectedRecords.push(allRecords[i].objAccount.Id);
}
}
confirm("Do you want to proceed without any Comments?");
var action = component.get('c.approvereject');
action.setParams({
"approvalId": selectedRecords,
});
//alert(JSON.stringify(selectedRecords));
action.setCallback(this,function(response){
var state = response.getState();
var records = response.getReturnValue();
if(state == 'SUCCESS'){
component.set('v.recordId', records);
alert("Approved Successfully");
$A.get('e.force:refreshView').fire();
}
else{
alert("Failed to Approve all Records");
}
});
$A.enqueueAction(action);
},
controller:
@AuraEnabled
public static void approvereject(Id approvalId){
String strComments;
list<Opportunity> lstARDs = [select ID, status__c from Opportunity
WHERE Approval__c=:approvalId ];
for(Opportunity objARD : lstARDs){
if(objARD.status__c==null)
{
objARD.status__c= 'Approved';
}
else if(objARD.status__c=='Rejected'){
objARD.status__c= 'Approved';
}
}
update lstARDs;
if(Approval.isLocked(approvalId)){
Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
req.setComments(strComments);
req.setAction('Approve');
//Getting Work Item Id
ProcessInstanceWorkitem pItem = [SELECT Id FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId =: approvalId];
req.setWorkitemId(pItem.Id);
// Submit the request for approval
Approval.ProcessResult result = Approval.process(req);
}
I have a custom Approve/Reject page and custom approval history.
How can I link both , like how to make it to go to the next approval step once it is approved/rejected.What am I doing wrong .pls let me know.
Here's the code.
JS:
approveall: function(component, event, helper) {
var allRecords = component.get("v.listOfAllAccounts");
var recordId = component.get("v.recordId");
var selectedRecords = [];
for (var i = 0; i < allRecords.length; i++) {
if(allRecords[i].isChecked ){
selectedRecords.push(allRecords[i].objAccount.Id);
}
}
confirm("Do you want to proceed without any Comments?");
var action = component.get('c.approvereject');
action.setParams({
"approvalId": selectedRecords,
});
//alert(JSON.stringify(selectedRecords));
action.setCallback(this,function(response){
var state = response.getState();
var records = response.getReturnValue();
if(state == 'SUCCESS'){
component.set('v.recordId', records);
alert("Approved Successfully");
$A.get('e.force:refreshView').fire();
}
else{
alert("Failed to Approve all Records");
}
});
$A.enqueueAction(action);
},
controller:
@AuraEnabled
public static void approvereject(Id approvalId){
String strComments;
list<Opportunity> lstARDs = [select ID, status__c from Opportunity
WHERE Approval__c=:approvalId ];
for(Opportunity objARD : lstARDs){
if(objARD.status__c==null)
{
objARD.status__c= 'Approved';
}
else if(objARD.status__c=='Rejected'){
objARD.status__c= 'Approved';
}
}
update lstARDs;
if(Approval.isLocked(approvalId)){
Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
req.setComments(strComments);
req.setAction('Approve');
//Getting Work Item Id
ProcessInstanceWorkitem pItem = [SELECT Id FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId =: approvalId];
req.setWorkitemId(pItem.Id);
// Submit the request for approval
Approval.ProcessResult result = Approval.process(req);
}
Greetings!
Can you please check the below blog which has the code for the lightning component along with the controller which might help you in achieving the required.
https://sfdcmonkey.com/2020/04/11/approval-screen-sfdc-lightning/
Kindly mark it as best answer if it helps so that it can help others in the future.
Warm Regards,
Shirisha Pathuri