how to detect if a page is refreshed?

Hi all

I’m using NAV 2013.

In a page I want to calculate total of amount field whet the page is opening.

I can do it inside OnAfterGetRecord() trigger.

But when I refresh the page the total changes, because the trigger runs again with the same code and data.

So I want to stop the calculation when the page is refreshing.

Does anyone know how to do that?

how to detect if the page is refreshed?

What kind of data of you are going to display ? Is the data coming from some another table or from same table ?

Same table Amount field

Do you mean to say user want to see the old value before/after updating the record ??

User wants a Balance field in Bank Acc Lgr Entry page.

Like this…

I want to add amount field to balance.

This is my code
OnAfterGetRecord()
Balance := Rec.Amount + xRec.Balance;

This works fine whine I open the page.

But when the page refreshed is messup.

Should work like this…

Document No.
Amount
Balance
Doc01 100 100
Doc02 200 300
Doc03 50 350
Doc04 150 500

May I understand the issue like you have create a code, which in the page trigger OnAfterGetRecord is updating the amount field? And then you don’t understand why it updates the field every time the user opens the page?

First, you should NEVER have actual code on pages. Only simple lookups etc.

Second, could you please explain exactly what it is that you’re trying to accomplish? And what if the user browses to the next record and back? Should it also not update the record here?

What I want is to know CAL code to detect if the page is refreshed by user?

You might want to try this:

OnAfterGetRecord()
Balance := Rec.Amount + xRec.Balance - xRec.Amount;

Thanks…

But then it shows like this…

Document No.
Amount
Balance
Doc01 100 100
Doc02 200 200
Doc03 50 50
Doc04 150 150

Any help on this?

This is from my system

3755.Untitled.png

This is correct. but this does not remain the same when the page refreshed…

This is after refreshed.

1581.Untitled2.png

And what code are you using instead of Thomas’?

This is mu code…

This is inside OnAfterGetRecord() trigger of the page

OnAfterGetRecord()
Balance := Rec.Amount + xRec.Balance;

Hi

I encountered this problem before. What happens is that each time you activate a colmn field of another record, the OnafterGetRecord" is triggered.

Normally you would settle for at Total field outside the tablebox, but i guess you could somehow build a subtotal if you really wanted. If someone have a better solution I would like to hear it.

If you know the position of each record in the table (ie. which record is the first, the second and so on), you would know which value to insert into the variable doing the following.

You could create a tempoary version of the table and copy filters and so on. You could then use some field for numbering and subtotal. It does not really matter as the temp table would sit in memory of the users computer only.

On the OnAfterGetRecord trigger you could count the “real” records and copy the subtotal from the Temp table with that same numbering…

Just an idear :slight_smile:

You would however need to rebuild the temp table if a change is made … :slight_smile:

Thanks Jan Schneider

But I don’t need a Sub Total field. Just the balance field.

Dont mind my wording of the fieldtype / name … I think this could be a solution. It’s a field which is the sum of all previous amount’s.

Can you show me a sample?

It depends on what your “Balance” field is (that is some information you did not share).

It is also unclear where your “balance” is originating from.

It is definitely a bad idea to write the “Balance” to the database, it should rather be calculated.

Next question is what should happen if the user changes the sorting of the page, should it again start with the first record shown ?

What you would need is a function which calculates the Balance by looping through the records:

Something like:

OnAfterGetRecord()
Rec2.COPY(Rec);
Balance := Amount;
WHILE Rec2.NEXT(-1) = -1 DO
Balance += Rec2.Amount;

Whereby Balance should be a Global of the type Decimal, rather than a field in the table.

It depends on what your “Balance” field is (that is some information you did not share).

It is also unclear where your “balance” is originating from.

It is definitely a bad idea to write the “Balance” to the database, it should rather be calculated.

Next question is what should happen if the user changes the sorting of the page, should it again start with the first record shown ?

What you would need is a function which calculates the Balance by looping through the records:

Something like:

OnAfterGetRecord()
Rec2.COPY(Rec);
Balance := Amount;
WHILE Rec2.NEXT(-1) = -1 DO
Balance += Rec2.Amount;

Whereby Balance should be a Global of the type Decimal, rather than a field in the table.