Getting a field to change based on a calculation when a value is entered or changed in a UD field

Sometimes our sales team has a commission value that will be paid on an order line and they don’t want to have to calculate what the corresponding rate would be to get that value. To keep all other functions of Epicor commissions running as intended, I created a UD currency field called OrderDtl_UD.CommAmt_c. I am trying to create a BPM that will populate the OrderDtl.RepRate1 with the corresponding rate to return the value in the UD field as the commission amount on that line. I did get it to work with a Data Directive, but if the UD field value is changed, it was showing the wrong value in the OrderRepComm field in the grid view of the Order Header->Order Totals tab and in the OrderHed.DocTotalComm on the same screen. It appears to be storing some kind of historical record and I think I need to reset those fields somehow and I’m not sure how to do it.

I’ve also tried a different approach to simply show a message, upon a change in the UD field, that includes a calculation saying what rate the user should enter into the OrderDtl.RepRate1 field. I cannot figure out how to get a calculated result into that message. Also, I would want the message to appear when the UD field is changed, not after clicking save. So, the Data Directive doesn’t really work for this. So, I’ve tried using a Method Directive with Pre and Post Processing and I cant get the change to trigger.

My last attempt, with the show message approach, was creating an After Field Change event in a customization for SO Entry. I can get the message to trigger when I want it to, but cannot figure out how to get the calculation into the code and return a value in the message. I have very basic C# knowledge and I’m sure there are ways to get this working.

I’ve tried:
private void OrderDtl_BeforeFieldChange(object sender, DataColumnChangeEventArgs args)
// ** Argument Properties and Uses **
// args.Row[“FieldName”]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
switch (args.Column.ColumnName)
case “CommAmt_c”:
if (Convert.ToInt32(args.ProposedValue) > 0)
MessageBox.Show(“Set the Commission Rate to” + " " + (args.ProposedValue / (DocExtPriceDtl - (DocDiscount-OrderDtl.DocTaxAmt))) * 100

I think the BPM is the best way to go, but I would appreciate any suggestions.


When I want something to happen before the record is saved, I might use a form customization too.

But, looked like your message is using raw integer values instead of strings.
Also… isn’t DocTaxAmt in the OrderRelTax table instead of OrderDtl?

Anyway… it’s REALLY slow today and I got to screwing around with this.
See attached results.
Note I used a different UD field and went WAY overboard with variables and messages but… still might be some ideas in there you can use.

Form Customization - Calc and Message before save.txt (6.4 KB)
App.SalesOrderEntry.SalesOrderForm_Customization_RepRate1BeforeSave_CustomExport.xml (19.4 KB)

1 Like

Hi Bruce,
Thank you so much for spending some time on this and providing the details. I appreciate your help and will give it a try. Have a great weekend!

Hi Bruce,
I used the code you worked up and replaced the UD field name with the one I created. I also changed the calculation to what is shown below (not using the less Tax Amount). The Calculated Value keeps returning as 0.00 when it should have a value. When I comment out to the individual components of the calculation the value returns correctly, but for some reason, I think it doesn’t like the division. Just hoping you can spot the culprit easily. Here’s that section of the script:

// Calculated value
int iCalcExample = Convert.ToInt32*((iCommAmt_c) / (iExtPrice - iDocDisc)) * 100;
// string sCalcExample = iCalcExample.ToString();
// string sCalcExample = String.Format("{0:F?}", iCalcExample, 2);
int numberOfDecimalPlaces = 2;
string formatString = String.Concat("{0:F", numberOfDecimalPlaces, “}”);
string sCalcExample = string.Format(formatString, iCalcExample);

Guessing it is the multiplication symbol after ToInt32.
i.e. you could try this instead
int iCalcExample = Convert.ToInt32((iCommAmt_c) / (iExtPrice - iDocDisc)) * 100;

BTW, did you know you can test your code while in script editor?
F5 key or Menu → Tools → Test Code.
Not perfect but I think that might have pointed you to the error too.

A couple final suggestions…
1.) Try to get on the EpicCare site and download the
“ICE 3.2 Tools User Guide” and the “ICE 3.0 Customization User Guide”.
Ref link:… EpicCare Login - EpicCare

2.) When your question is more generic C# LINQ, SQL, etc… Google might actually be faster, better than this site.

This site is great for getting help with your Epicor specific question.
e.g. Epicor specific questions about EpiDataViews?
— this.edvOrderDtl = ((EpiDataView)(this.oTrans.EpiDataViews[“OrderDtl”]));

v.s. a generic question about C# variables/calculations, etc…
int iCalcExample = Convert.ToInt32((iCommAmt_c) / (iExtPrice - iDocDisc)) * 100;
Not that you won’t get responses to those question too, just might not be as much feedback for those as would be for Epicor specific questions.

Good luck… once you get over the initial learning curve, this stuff can actually be kind of fun… somedays.

and finally…
te sample customization as it is will be suscptable to (a lor of ) runtime errors.
e.g. especially division by zero if not all of your fields were populated.
So… you might want to look at enclosing some code in “try catch”
Where you can find many examples If you search Google for the key words: c# try catch
e.g. c# - How using try catch for exception handling is best practice - Stack Overflow

Thanks again for your advice Bruce! Will do. You know, people ask me why I like doing this kind of work, and my response is always that it’s like a video game, I can’t let it beat me!

Have a great day!