BPM to email before and after values

When anyone changes an OrderHed.NeedByDate or OrderHed.RequestDate we want to send an email that provides the old date as well as the new date for comparison. I have tried a few different bits of code from this forum, but continue to run into various compilation errors. Can someone suggest how I can best pull the “old” date into the BPM? I was trying to query the database table instead of the ttOrderHed table and assign the value to callContextBpmData.Date01 and Date02. If there is a better way, please let me know.

You can pull in the old date by reading OrderHed using the OrderNum value from ttOrderHed. You can then compare that date to the temp table value (new value). If this is too vague I can send an example.

Have you considered writing those fields to the change log? It won’t
email, but will keep track of when and who changed the selected fields and
the values.

2 Likes

Dan,

I was trying to do this, but everything I tried gave a compilation error. Not sure where I am getting the syntax wrong. I would appreciate an example.

Thanks Randy, we do have the change log tracking this as well, but the request came to email it out so it can immediately be evaluated for impact rather than discovering the change in a post mortem or another dashboard (our team is beginning to experience death-by-dashboard-overload).

Here is an example of doing this in a pre-processing method directive with no condition just relying on the Update method firing.
int OrderNumber = 0;
foreach (var TempOrder in (from row in ttOrderHed where row.Company == Session.CompanyID select row))
{
if (TempOrder.RowMod == “U”)
{
Epicor.Customization.Bpm.InfoMessage.Publish("New Date = " + TempOrder.NeedByDate.ToString());
}
if (TempOrder.RowMod == “”)
{
Epicor.Customization.Bpm.InfoMessage.Publish("Old Date = " + TempOrder.NeedByDate.ToString());
}
}

2 Likes

Thanks Dan, that should give me the minimum functionality I needed. I am curious how I would link to other table values such as the Customer.Name field by linking the ttOrderHed.CustomerCustID to the Customer.CustID. This was the type of code I tried to copy from other threads to capture the NeedByDate originally and thought it would translate over to the Customer table, but I never got it to work.

Erp.Tables.OrderHed OrderHed = (from OrderHed_Row in Db.OrderHed
where OrderHed_Row.Company == ttOrderHed.Company &&
OrderHed_Row.OrderNum == ttOrderHed.OrderNum
select OrderHed_Row).FirstOrDefault();

if(OrderHed != null)
{
callContextBpmData.Date01 = OrderHed.NeedByDate;
}

More half baked code… sample how to join ttOrderHed to Customer

var TempOrder = (from row in ttOrderHed
join cust in Db.Customer
on row.CustNum equals cust.CustNum
select new
{cust.Name});
foreach (var item in TempOrder)
{
Epicor.Customization.Bpm.InfoMessage.Publish("Customer = " + item.Name);

}

1 Like

No worries Dane, I’ve seen more than once requests like this where they didn’t know the Change Log was even available.

Fantastic! Looks like I am off to the races, though I don’t 100% understand your code, I have managed to extend it further. Is there anything risky about the way I am extending this code to link to other tables? Or perhaps am I including extraneous code (e.g. the second time I reference “from row in ttOrderHed” seems redundant)?

Edit: Just to be clear, the code below was tested and functioned correctly.

var MyCustomerRec = (from row in ttOrderHed
join MyCustomerRecRow in Db.Customer
on row.CustomerCustID equals MyCustomerRecRow.CustID
select MyCustomerRecRow).FirstOrDefault();

if(MyCustomerRec != null)
{
var MySalesTerRec = (from row in ttOrderHed
join MySalesTerRecRow in Db.SalesTer
on MyCustomerRec.TerritoryID equals MySalesTerRecRow.TerritoryID
select MySalesTerRecRow).FirstOrDefault();

if(MySalesTerRec != null)
{
callContextBpmData.Character01 = MyCustomerRec.Name;
callContextBpmData.Character02 = MySalesTerRec.TerritoryDesc;
}
}

2 Likes

I never knock something that works. You are right about the extraneous code and you could do this in one query with two joins with just a couple other minor changes. Good work.