Hi. I need a value in a tablefield to be the result of a little calculation. I was searching for an onCalcFields trigger, but can’t seem to make it apear. Or maybe this is not how it is done. It is possible to assign code to a field’s value, right? or…?

Thanks in advance, for any answers :slight_smile:

Hi MortVader,

I’m a bit confused as to what You want to do…

The field You want calculated must first of all exist in the table-definition.
If the result is a Decimal, then the field has to be of that DataType etc.
You propably already have done that [;)]

Next, if the result is perhaps the sum of a series of records in another table, You can define the new field, as a FieldClass = Flowfield.
Then in the CalcFormula-property You define the way the value are calculated. Now Navision will calculate the value every time it is presented in the GUI, or if You do a CALCFIELD in Your code. You will propably find a great number of threads on Flowfields in here.

If the calculation is too complex for a Flowfield to be used, You must write code that can do the calculation for You.
If the calculation it self is triggered by the change of a value in a field, then the OnValidate-trigger of this field is where You want to write the code.

I hope this leads You in the right direction.

Thanks for your reply.

The calculation is too complex for a normal flowfield, so I need some coding to be able to present the value in the GUI.
But where do I put the code? I was looking for an onCalcFields trigger for it :slight_smile:


If you want only show values on the form, then you can create variable in the form and assign value in OnAfterGetRecord trigger. Then add textbox with your variable name in source expression. Only problem, that you will not be able to filter on that field.

That depends on wich “events” that could cause the value to change.

You’ll have to insert the code in the appropriate trigger.

Say I have a field in the Currency-table, that tells me how many customers and vendors have this currency-code attached, then I would write code in the OnValidate-trigger of the Currency Code-field in both the Customer-table, and in the Vendor-table.

You’re missing the point about flowfields. Flowfields are not updated by the fields they total/max/whatever, their value is retrieved from where the flowfield is defined. The Balance field on the Customer Card is not updated every time a record is written into the ledger. The ledger tables are designed to keep totals (sumindexfields), and the flowfield is nothing more than a little command to get one of those totals.

By the way, if you want to know how many customers/vendors, you can design a ‘count’ type flowfield (you’d just need one for vendors and one for customers), and the right data type would be integer, not decimal, as you would not find 2.5 customers with a certain currency code. I’d have to play around with it to see if it would do what I think you want, but that’s where I’d start looking.

Hi Daniel,

I think that You are missing something here…

I’m trying to help Morten to find a way to solve a specific task.

I believe I said that a Flowfield are calculated whenever it is presented in the GUI, or when we do it by using CALCFIELD…
I also said that if the calculation is too complex for it to be done by using a flowfield, then he would have to manually update his field from the source-table.

The example with the count of vendors and customers, was only an example to show Morten a scenario that demands for a manual update, and where he would have to do it.
The decimal-dataype comment are not at all related to the customer/vendor-thing.

Yes, this could be solved like Viktoras suggests, but I was looking for a more general way of doing it. By putting this functionality directly into a table field, I would not need to paste the same code onto all the forms which needs to display this info.

But I’m starting to think I may have to…

Thanks for your suggestions though, everyone!