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
// 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
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.
just for fun, i did a little refactoring of your c#…
changed the queries to lambda
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)
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;
}
}