Form trigger for when refresh/update?

ccbryan63ccbryan63 Member Posts: 115
Is there a form trigger that fires when the form is refreshed or updated?

I have added a "Total Amount" field to Form 256 Payment Journal. When the batch name is chosen in the combo box, the screen does a setrange on the General Journal Line table. I have a little piece of code that sums the Amounts of the displayed records to the variable that is the source code of the "Total Amount" field. But I can't find a trigger to put the code in. If I put it in form.OnOpen() it works, and displays the total amount of the batch that the form defaults to, but I can't find a trigger that runs the code when the batch is changed.

Putting the code in the OnValidate and OnAfterValidate of the batch combo box doesn't work.

Any suggestions?

Answers

  • awarnawarn Member Posts: 261
    OnAfterGetRecord should do it. If the form is somehow refreshed, then navision 'gets' the record again from the DB, hence OnAfter'Get'Record.

    -a
  • SavatageSavatage Member Posts: 7,142
    Globals: JournalAmt type Decimal

    On Trigger Add
    OnAfterGetCurrRecord()
    UpdateSums;
    
    Create Function
    UpdateSums()
    BEGIN
     GenJnlLine.COPY(Rec);
     GenJnlLine.CALCSUMS(Amount);
     JournalAmt := GenJnlLine.Amount;
    END
    
    Add text box at bottom of the form
    SourceExp : JournalAmt

    If I remember correctly you need to then add a SumIndexField(Amount) to one of the keys of the Gen Journal Line table
  • ccbryan63ccbryan63 Member Posts: 115
    I ended up taking care of it with a timer. Kluge maybe but it works like a charm.
    Form TimerInterval property = 1
    GJL = new global record variable Gen Jnl Line
    Form OnTimer() trigger:
    
    
    TotAmount := 0;
    GJL.SETRANGE("Journal Template Name","Journal Template Name");
    GJL.SETRANGE("Journal Batch Name","Journal Batch Name");
    IF GJL.FIND('-') THEN BEGIN
       REPEAT
          TotAmount := TotAmount + Amount
         UNTIL GJL.NEXT = 0;
       CurrForm.UPDATE(FALSE);
    END;
    

    (I had forgotten the CALCSUMS function :oops: )

    Just for grins I tried putting this code in OnAfterGetRecord and I got an error: "There is insufficent memory (stack) to execute this operation. This can be due to the way recursive function calls are used in the program." So then I put Savatage's code in OnAfterGetRecord and got the same message, so guess I'm sticking with my messy(?) solution.
  • SavatageSavatage Member Posts: 7,142
    ccbryan63 wrote:
    So then I put Savatage's code in OnAfterGetRecord and got the same message, so guess I'm sticking with my messy(?) solution.

    That is the exact code I use and it's the OnAfteGetCurrRecord Trigger.
    Works fine
    here's the old orig post
    http://www.mibuso.com/forum/viewtopic.php?t=7692
Sign In or Register to comment.