accumulated balance in page 20

kanikakanika Member Posts: 247
edited 2018-02-07 in NAV Three Tier
Hi experts!! NAV2017

I need to add a field on the page with the accumulated balance, like the example


kjad2kdc4x2s.png


I wrote this code in the OnAfterGetRecord () trigger

IF NOT blnPrimero THEN BEGIN
decAcumulado:=0;
blnPrimero:=TRUE;
END;
decAcumulado+=Amount;

but it does not work

please any suggestions!!

Answers

  • allenyyzhouallenyyzhou Member Posts: 142
    Hi

    Just my personal suggestion.

    Add accumulated field in Page is not a good practice. Do this in report.
    If you really want to do, add accumulated field in table, create a new page and calculate it by action.
  • kanikakanika Member Posts: 247
    edited 2018-02-08
    but why???
    why is not a good practice??
    and
    why a new page?
  • allenyyzhouallenyyzhou Member Posts: 142
    Hi

    Well, performace is one concern, and the control of filtering, sorting is another concern.
    Again, just my personal opinion.
  • kanikakanika Member Posts: 247
    I thank all the opinions, it is for having a more extensive information
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2018-02-08
    I would not be concerned about any performance issues. What you do is a simply math operation, you would have to run tens of thousands of them to see any impact.

    The trouble with Pages is the control of calculation. How do you reset the blnPrimero when user clicks one of headers and change soting order? Or add a filter to get a subset of records?

    I would agreed with @allenyyzhou - do it on a report. This is the a place where you can get it working much easier.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • kanikakanika Member Posts: 247
    the question is that as it works well except the first line, from the second the balance is correct until the end

    dcb7s03p1jce.png
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2018-02-08
    OnAfterGetRecord is not guaranteed to fire only once on the page . And this is exacly what happend here: it was fired 5 times: 1st on 1st line, then on 2nd, then on 3rd line and then 2 times more on the first one.

    Even order in which the records are fetched is not guaranteed. Try scrolling a few lines an then try PageUp or PageDown.

    If you want do do this on the page you would need to build much more complicated logic to control when to add up the amount and when to reset it back to 0.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Sign In or Register to comment.