How to show total Amount in payment Journal

Hi All
I need to create a total on the bottom of the screen on payment journal screen that shows the addition of all lines - amount field. The pattern I’ve tried is creating a page action that refresh on open that update subpage function to populate fields on new sub page table like:

                    CurrPage.SetSelectionFilter(SelectedPayJnlLines);
                    if SelectedPayJnlLines.FindSet() then
                        repeat
                            LinesCount += 1;
                            TotalAmount += SelectedPayJnlLines.Amount;
                          
               until SelectedPayJnlLines.Next() = 0;

Two questions:

  1. Is there a way to refresh total automatically each time user updates the amount field?
    2.Is there a function to select all lines without using CurrPage.SetSelectionFilter. I can use SetRange on Batch ID and Template but wondering if there is a better method to select all lines on a given page even if the use selects none (yes, by default 1 line is always selected

You might find the answer on the Base App. Like the totals from the sales order subform. The trigger is the ‘OnAfterGetCurrRecord’:

image