Showing Totals for Sub Pages in Microsoft Dynamics NAV 2009

Hello together,

this is the first time that I try to blog - ever in my life time. So please be tolerant if you find some weird works or unclear phrases.
Some of you might know me - I'm member at DUG since the year 2000 and doing NAV since 1999.

Now let's start the story.

Many times NAV developers face the request from the customer to show the total amount of all lines in document forms.
And there are a lot of suggestions running around including using sendkeys functions to update the page when showing the document amount in the "General" FastTab.
To show the total line amount there is one of the options - even though not the best one - at least in my opinion - and that is what I'm sharing here.

How to do it otherwise?

There are two additional approaches to this issue.

Approach 1: Extend the SubPage (ListPart)

Just above the repeater we will ad a fixed layout group with four field controls, the first two will not have a source expression. The other ones will have the caption and the total amount as source expression.


Of course we do also need to define the TotalLineAmount variable as decimal in the globals.
Now as we do have our stage, we can start the play.

One more consideration: When just calculating a normal flowfield we do have the problem - and that is the biggest issue for displaying the correct total - the total is updated only when the current line has been written to the database.
So for overcoming this issue we use a small trick:

We create a new function in the page called CalcTotalLineAmount - or even better we could do that in the table so we can call it from everywhere.
This function will return a decimal value representing the total of the document:

As you can see we are excluding the current line number from the filter so after calling the CALCSUMS we are getting the total amount of all "other" lines. Then we add the line amount of the current line manually to the result.
This way we make sure to receive the correct line amount for the current record and not from the database. 

All we do need to do now is to call this function, most probaly at different places.
One nice place to call this is the "OnAfterGetRecord" trigger.
Other nice places would be the OnValidate triggers in the form which will have impact on the amount of the lines.
Usually these are fields like quantity, unit price, discount - and of course the amount field itself;
We just place the following code into the trigger:


This should be it Smile

But we have been talking about a second approach - so here we go:

Approach 2: Utilize the fact box.

The fact box already shows some information for the current line, so it would just be a small extension to also show the document amount.

All we need is one more control in the page 9087 for the sales document as an example.
We where clever in the previous approach when we created the CalcTotalLineAmount function in the table rather than in the form. This way we can use the function directly as the source expression for the new field in the fact box:

That was actually it, just run the sales order form - or any other form using this Sales Line Factbox - and see the result:

 But of course there is no rose without a thorn. This one only updates the total amount when you leve the current line and go to the next or previous one.

The next time I will blog about the opportunities to perform real "Inter-Page-Communication" on the Role-Tailored Client which allows the direct access to the master page from the sub page.


Comment List