Payment Entry Approval Control (BPM)

Hi All,

Looking for some advice on a BPM I’m working on to add approvals and lockdowns of a payment entry.

The workflow is:

  • Group Created (APChkGrp)
  • Payments Added (CheckHed)
  • Approve All Payments (APChkGrp)
  • Approval Data <user, datetime> Stamped (CheckHed)
  • Group/Payments Locked (APChkGrp,ChecHed)
  • Only FA’s Can Post

UD Fields Created:
APChkGrp_UD.ApproveAll_c
CheckHed_UD.Approved_c
CheckHed_UD.ApprovedBy_c
CheckHed_UD.ApprovedDate_c

I’ve tried to come at this with a low code/no code approach but seem to be hitting a brick wall with setting this up between the 2 methods involved (Erp.BO.APChkGrp & Erp.BO.PaymentEntry). I’ve since turned to a C# approach but fairing no better.

Currently standing at using a post processing on Erp.BO.APChkGrp.Update:
Condition: The ds.APChkGrp.ApproveAll_c field of the updated row is equal to the true… expression.
If True:

string approvedBy = Session.UserID;
DateTime approvedDate = DateTime.Now;

foreach (var grpRow in ds.APChkGrp)
{
    if (grpRow.ApproveAll_c == true)
    {
        string apChkGrpID = grpRow.GroupID;

        var checks = (from chk in Db.CheckHed
                      where chk.GroupID == apChkGrpID
                      select chk);

        foreach (var check in checks)
        {
            check.ApprovedBy_c = approvedBy;
            check.ApprovedDate_c = approvedDate;
            check.Approved_c = true;
        }
    }
}

The error of “CS1061 ‘APChkGrpRow’ does not contain a definition for ‘ApproveAll_c’ and no accessible extension method ‘ApproveAll_c’ accepting a first argument of type ‘APChkGrpRow’ could be found (are you missing a using directive or an assembly reference?)” is popping up and, not being too well versed in C#, my troubleshooting is limited.

Any advice on if a low code/no code option is viable or, if not, any troubleshooting pointers on where I’m going wrong with the C# would be greatly appreciated.

Edit to add, I’m using ds.APChkGrp

Rgds,
Barry

So there are a couple of things here that will need to change. Firstly, in BPMs, the syntax for UD Fields is a little different. Instead of using grpRow.ApproveAll_c, you need to use the syntax grpRow["ApproveAll_c"]. That should solve the error you’re getting.

The bigger issue is the way you’re doing the update on the UD Field in the check rows. Broadly speaking, it is not recommended to directly update Database rows (using your Db.CheckHed linq query).

The recommended method would be to call Business Object method that Epicor provides for these. Doing that in a foreach statement in a BPM can be kind of a pain. My usual method would be something like this:

// Conditional Block
// The <specified field> ChckGrp.ApproveAll_c has been changed from 'false' to 'true'
// Custom Code Block to execute when the above conditional is true

chkGroupID = ds.ApChkGrp.Select(s => s.GroupID).FirstOrDefault();
approvedBy = Session.UserID;
approvedDate = DateTime.Now; // Make these BPM Level Variables
// Add an InvokeFunction widget, passing the three variables above to a function.

Then, create an Epicor function library which updates your checks using the BO Method for each check in the group.

/*
    First function
    Request Params: CheckGroupID, ApproveUser, ApproveDate
*/
    var APCheckList = Db.CheckHed.Where( x => x.GroupID == CheckGroupID ).Select( s => s.CheckNum ).ToList();
    

    foreach ( var chk in APCheckList )
    {
        this.ThisLib.SecondFunction( chk, ApproveUser, ApproveDate );
    }

Then in your second function, you can use widgets / low or no code to call GetByID on the checks, and update the Approved_c, ApprovedBy_c, and ApprovedDate_c fields using the Update Method.

This will allow you to loop through the checks and approve them using the correct BO Methods, rather than a DB direct update of the rows, which can be bad in a lot of cases. It’s less dangerous with UD Fields, but I still wouldn’t recommend it.