Issue with BPM

Hey everyone, having some issues with, what I thought, would be an easy BPM.

What I’m looking to accomplish is have the Labor Rate of an employee auto-magically update to the value of the ProdLaborRate once the employee is assigned to a Resource group.

I’ve created a Post-Processing method directive on the Erp.BO.EmpBasic.Update method code. Condition is as follows


Custom Code (Executed synchronously):

// Change row in the EmpBasic table
var ttEmpBasicRow = this.ds.EmpBasic.FirstOrDefault();
if (ttEmpBasicRow != null && !string.IsNullOrEmpty(ttEmpBasicRow.ResourceGrpID))
{
    var resourceGrpID = ttEmpBasicRow.ResourceGrpID;
    
    // Fetch the ProdLabRate from the ResourceGroup table
    var resourceGroup = (from rg in Db.ResourceGroup
                         where rg.ResourceGrpID == resourceGrpID
                         select rg).FirstOrDefault();

    if (resourceGroup != null)
    {
        // Update the LaborRate in the EmpBasic row
        ttEmpBasicRow.LaborRate = resourceGroup.ProdLabRate;
    }
}

Yes the BPM has been saved and Enabled. First time I ran through it I forgot the check box lol

1 Like

I formatted your code, so I could read it better.

post process is going from the database to client, so you want to do pre-processing to set the data between the client to the database.

6 Likes

I’ll give that a shot, thanks Greg!

1 Like

I would also change your condition from the current condition to the <specified field> field has been changed from <any> to <another> using an empty string as the initial value, and leaving the changed value as “another”. The reason is that with your current condition, it will fire your custom code when any change is made on records that already has a Resource Group ID.

2 Likes

@kve I’ll make that change

Thank you @gpayne and Kevin much appreciated. This is now working as intended!

2 Likes

just for fun, i did a little refactoring of your c#…

  1. changed the queries to lambda
  2. moved part of your if statement into the first query (no need to select a record that doesn’t have a resource group… might as well filter it during the query)
  3. eliminated a couple of reassignement variables… just use them as is.
// Change row in the EmpBasic table
var ttEmpBasicRow = this.ds.EmpBasic.Where(x => x.RowMod != "" && x.ResourceGrpID != "").FirstOrDefault();

if (ttEmpBasicRow != null){
    // Fetch the ProdLabRate from the ResourceGroup table
    var resourceGroup = Db.ResourceGroup.Where(rg=> rg.ResourceGrpID == ttEmpBasicRow.ResourceGrpID).FirstOrDefault();

    if (resourceGroup != null){
        // Update the LaborRate in the EmpBasic row
        ttEmpBasicRow.LaborRate = resourceGroup.ProdLabRate;
    }
}
4 Likes