2

I have requirement where an user should not be able to submit a master record for approval until all the related child records are approved.

Submit for approval button on approval history related list cannot be removed. So, this is not an option.

The approach I was thinking is to have a custom field on the master record which specifies whether all child records are approved and add that field in the entry criteria. S0, the record won't be submitted as it does not satisfy the entry criteria. But I need to inform users why they are not able to submit the record. So, I want to customize the error message as well. I have done some search and could not find anything.

Can anyone please let me know if this is possible or suggest any workaround for the above scenario?

2 Answers 2

2

I've made such button in the past and actually I'm not too happy with it:

  1. Users have to be trained to click the non-standard button
  2. A formula text field with "TODO list" sits right next to the data and is reportable on. And you might be better off referencing this formula field in entry criteria in approval if they're very complex
  3. A small embedded VF page is easier to maintain if your colleagues aren't too good with AJAX toolkit

Here goes:

{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}

var poId = '{!Purchase_Order__c.Id}';
if(poId == ''){
    poId = window.location.pathname.replace("/","");
}
var results = sforce.connection.query("SELECT PO_Validation__c, Requestor__c, Approved_Amount__c, Total_Amount__c, PO_Item_Count__c, Required_Delivery_Date__c,Total_Exceeds_Approved_Budget__c, Reason_for_Discrepancy__c FROM Purchase_Order__c WHERE Id = '" + poId + "'");

var po = results.records;
if(po.PO_Validation__c != 'Valid'){
    var msg = 'This Purchase Order cannot be sent for approval before following errors are amended: \r\n\r\n';
    if(po.Requestor__c == null){
        msg += '"Requestor" is blank\r\n';
    }
    if(po.Approved_Amount__c == null){
        msg += '"Approved Amount" is blank\r\n';
    }
    if(po.Total_Amount__c == 0){
        msg += '"Total Amount" is 0\r\n';
    }
    if(po.PO_Item_Count__c == 0){
        msg += 'There are no PO Items\r\n';
    }
    if(po.Required_Delivery_Date__c == null){
        msg += '"Required Delivery Date" is blank\r\n';
    }
    if(po.Total_Exceeds_Approved_Budget__c == 'Yes' && po.Reason_for_Discrepancy__c == null){
        msg += 'Total exceeds the budget but "Reason for Discrepancy" is blank\r\n';
    }
    alert(msg);
} else {
    // Part based on standard Submit for approval button
    if ((Modal.confirm && Modal.confirm('Once you submit this record for approval, you might not be able to edit it or recall it from the approval process depending on your settings. Continue?')) || (!Modal.confirm && window.confirm('Once you submit this record for approval, you might not be able to edit it or recall it from the approval process depending on your settings. Continue?'))) 
        navigateToUrl('/p/process/Submit?retURL=%2F' + poId + '&id=' + poId,'DETAIL','submit');
}
1
  • I did something similar but with a full VF page which checks if it can submit and does so or else shows a message. The page content is also the documentation explaining when a record can be submitted.
    – Marc
    Commented Mar 14, 2013 at 16:43
1

It isnt possible to customise the error message so the only plausible option seems like a custom button (which is what I've seen done in the past)

You can remove the Default Submit for Approval page detail button.

To get rid of it from the Approval History related list, you can use a bit of Jquery sorcery in the sidebar. Heres how http://boards.developerforce.com/t5/General-Development/To-remove-quot-Submit-for-Approval-quot-button-from-the-Approval/td-p/272721

Then create your own custom button, which calls out to a Webservice method in a class, or via the Ajax toolkit checks if the child records have been approved first.

For this you could have a field on the child record - Approved with a 1 or 0 value and then two Rollup Summary fields, one a count and another a filtered Count where Approved = 1. When child record count = approved child record count, then allow to submit parent for approval.

If valid, you can redirect to the URL for Submit as

 {!$Action.Parent_Object__c.Submit}

If not, display an error message as a JavaScript alert.

Here something you can reference http://boards.developerforce.com/t5/General-Development/Approval-Process-How-to-Edit-Pop-Up-Warning-Message-on-Clicking/td-p/275967

You must log in to answer this question.

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