Now it is time for me to share what I did (to help any other users trying to accomplish the same thing). A predecessor created a Standard Data Directive on OrderHed that triggered for a machine order (not a parts order) when the NeedByDate, ShipVia, or FOB changed from any to another. It would send an email that would provide the order number, machine serial number, the current values of the 3 fields that possibly changed, then the open order lines with a part number. It was rather basic and users (especially salespeople who were travelling) wanted more information to help them identify the Customer and what changes occurred.
After unsuccessfully trying to get the “before” value on the Standard Data Definition, I created a Pre-Processing Method Directive on SalesOrder.Update.
So I used 2 conditions. The first one checks some UD fields that identify this is a “Machine” order and not a parts order. The second condition checks that one of the three fields has changed from any to another:
Then I set the order number as a variable:
My predecessor had a custom code widget to get the salespersons email addresses (some minor tweaks were needed to get it to work in a Method directive compared to a Data Directive; like tt becomes ds.) That custom code looks like this:
//look at incoming SalesRepList (~ delimited) and get emails
var internalSalesEmails = new List<string>();
var salesRepString = ds.OrderHed.Select(r=>r.SalesRepList)
.FirstOrDefault();
if(salesRepString != null)
{
//split the string into a list of Sales Rep Codes on ttOrderHed
var salesRepList = salesRepString.Split('~').ToList();
if(salesRepList.Count>0)
{
var roleCodeList = Db.SalesRep.Where(r=>r.Company == Session.CompanyID
&& r.RoleCode == "Agent")
.Select(r=>r.SalesRepCode)
.DefaultIfEmpty()
.ToList();
//add "Sales" work force ID to roleCodeList
roleCodeList.Add("Sales");
//reduce salesRepList down to just internal Sales by removing the roleCodeList values
var internalSalesRepList = salesRepList.Except(roleCodeList).ToList();
// lookup email addresses
foreach (string RepCode in internalSalesRepList)
{
var tempEmailList = Db.SalesRep.Where(e=>e.Company == Session.CompanyID && e.SalesRepCode == RepCode)
.Select(e=>e.EMailAddress)
.DefaultIfEmpty()
.ToList();
string tempEmailString = string.Join("",tempEmailList);
internalSalesEmails.Add(tempEmailString);
}
//create email string
SalespersonEmail = string.Join(";",internalSalesEmails);
}
}
Then I filled a table by query (to grab the open lines, line number, and Machine part number):
The query looks like this:
With only the 3 display fields I needed:
Then I set the Previous values as variables, beginning with the NeedBy Date:
Then with Calvin’s help (and other tidbits gleaned from EpiUsers threads), Set the date (as another variable) without the time:
Then I set another variable for the New NeedBy Date (short version):
Then I set another variable for the Previous Ship Via Code:
The I set another variable for the Previous Ship Via Description:
Then I set another variable for the Previous INCOTERM (or FOB) Code:
Then, with Olga’s tip (notice the column as FOB1), I added the INCOTERM description:
Then I wanted to add some text that would be conditional (to identify the changed values and also show the unchanged values). I did this with more variables for NeedBy Date, ShipVia, and INCOTERM/FOB. Here is the expression for the NeedBy Date:
The ShipVia (the new values are carried in the ds. table):
The INCOTERM/FOB:
The email then pulls the conditional variable in. The customer name gets pulled through on the ds.OrderHed table as does a formatted version of the ship to address. Then I show my conditional statements to clarify what changed (showing the previous value and the new value) or stating that the field did not change and showing what that value is. I also had to add three spaces then Ctrl+Enter to get my line returns to show properly in the email. I also showed in the message which user made the change to the order, what the order stage is, and then showing the order lines:
Here is what the email looks like:
Hopefully this will help other users.
I am open to critiques on how I could have done this better.