Question

Calculation between two fields

  • 8 April 2022
  • 6 replies
  • 331 views

Hi All,

 

I hope someone can help as I am not a full time coder and this part of the customisation has me flumuxed!

I have created a UD field in “PODetail” called “TonRte_c”, I have then pulled through a Foreign Key from the “Part” Table called “Part.GrossWeight”

 

The calculation seems simple but it has me stumped, it compiles ok but does nothing.

(PODetail.ScrUnitCost / Part.GrossWeight) * 1000 - This should return the result back to “TonRte_c”

 

private void PODetail_AfterFieldChange(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 "TonRte_c":
            
                decimal TonRte_c = (decimal)args.Row["PODetail.ScrUnitCost"] / (decimal)args.Row["Part.GrossWeight"] * 1000; 

                break;
        }
    }

 

Any help on this would be very appreciated.

 

Many thanks in advance

Steve


6 replies

Userlevel 1

Hi Steve,

What exactly are you trying to do ? I’m not sure what you have there makes sense or I’m missing something.

 

Hi Dragos,

 

I have two fields in PODetail:

  • Unit Price
  • Gross Weight - (Field pulled from Part Table)

I want a calculation as follows: (UnitPrice / GrossWeight) * 1000

 

This calculation should then populate a UD field call “TonRte_c”

 

Hope this makes more sense.

Steve

Userlevel 1

Hi Steve,

The AfterFieldChange event you got there is the one fired when TonRte_c is changed, that’s why I said it doesn’t make much sense. This sounds like a BPM on PO.Update.Pre. You can call Part.GetByID there to get your part weight and then calculate the formula. Another thing you need to consider is dividing by 0 - you can’t have that. 

Userlevel 1

I haven’t tested the below but it’s a good start. Replace Number02 with your TonRte_c

 

 

Hi Dragos

 

I have set this up as you suggested with “GrossWeight != 0” so this should only calculate where we have a value in the GrossWeight thus ignoring the divide by 0 scenario.

 

When openeing a PO where I know there are values I receive the error below, Any further suggestions would be appreciated.

 

Userlevel 1

Roughly how Epicor saves records: if you change something on the PO line and save, Epicor will create 2 records in ttPODetail: one with the unchanged line (RowMod=’’) and another one with the changed line (RowMod=’U’ if you’re updating the row, ‘A’ if it’s a new line). Those 2 lines are sent to the SQL server which will compare them and update the tables in the database accordingly.

If you’re not changing any lines, ttPODetail will be empty - which is what the error says. I’m afraid this is not as straightforward as I thought.

What I would do: first, update all of your current POs with DMT. Second, add a condition to that BPM at the beginning like below:

Again, this is just a starting point, you’ll need to test this properly. Finally, you need to take into account on-the-fly parts (if you have any). If you have one on the PO and trigger GetByID with its part number, you’ll get an error as the Part doesn’t exist in the table. You’ll need a condition for that one too.

The DMT part will cover all of your existing POs while the BPM will cover all newly created or changed POs.

Reply