Updating other fields based on changes in a flow field

blhblh Member Posts: 24
This is sort of a long explanation so bear with me! One department in my company has an excel spreadsheet from which we import costs and other information into a table in NAV through an XML port. The table in NAV is called the Replacement Cost table. In another table called the Customer Pricing table we have a flow field called Replacement Cost which looks up the Replacement Cost from the Replacement Cost table. By choosing various criteria like shipping location, item etc. the Replacement Cost flow field in the Customer Pricing table will change. For instance in the On Validate trigger in the item field I have the following code to recalculate the Replacement Cost field: “CALCFIELDS("Replacement Cost");”.There is another field in the Customer Pricing table called Unit Price which calculates the unit price of an item based on the value in the Replacement Cost flow field and a couple of other fields. What I want is for the Unit Price to be updated every time the value in the Replacement Cost flow field has changed. I have code to calculate the Unit Price in the On Validate trigger in the Replacement Cost flow field in the Customer Pricing. It reads as follows:

IF "Margin Type" = 0 THEN BEGIN
"Unit Price" := "Replacement Cost" + Margin + "Rebate Amount"
END
ELSE
"Unit Price" := "Replacement Cost" + ("Replacement Cost" * (Margin/100)) + "Rebate Amount";

The Unit Price is not updating when the Replacement Cost value changes. The Unit Price field is not updating when someone changes the value of one of the fields that changes the Replacement Cost value. For instance when somebody changes the item field the Replacement Cost changes and thus, in my thinking at least, the unit price should be recalculated. Where have I gone wrong? Also how can I ensure that whenever a new replacement cost is imported into the Replacement Cost table that the Unit Price is updated in the Customer Pricing table based on the new cost? Thanks for any help that can be provided.

Answers

  • MBergerMBerger Member Posts: 413
    you should trigger this from changes in the underlying table, not the flowfield. I'd suggest adding some code after importing the xml file into your replacement cost table to recalculate all the records in the customer pricing table that are affected.
  • blhblh Member Posts: 24
    MBerger,
    Thanks for the suggestion. I put in code in the XMLport to calculate the replacement cost and the unit price after the import. It works like a charm. I appreciate your help.
    blh
Sign In or Register to comment.