Onaftergetrecord trigger

Hi, I'm new to NAV/BC development and trying to figure out how to use the onpredataitem and onaftergetrecord trigger in a report dataset. I have read the online documentation and also used the txt2al tool to look at the code used to generate some of the reports (sales invoice, detail trial balance).. I'm still having a hard time wrapping my mind around how this would work. Here is the code I'm working with, I have three tables: sales invoice header, sales invoice line and location. I am trying to figure out how to use the onpredataitem and onaftergetrecord triggers to pull the location name rather than adding another dataitem. The code I have today is below...

Thanks in advance for your help!

report 50116 "Test Report"
UsageCategory = Administration;
ApplicationArea = All;
RDLCLayout = 'rdl_layouts\test.rdl';

dataitem("Sales Invoice Header"; "Sales Invoice Header")
RequestFilterFields = "Document Date";
column(No_; "No.") { }
column(Document_Date; "Document Date") { }
column(Posting_Date; "Posting Date") { }
column(Sell_to_Customer_Name; "Sell-to Customer Name") { }
dataitem("Sales Invoice Line"; "Sales Invoice Line")
DataItemLink = "Document No." = field ("No.");
column(Item_No_; "No.") { }
column(Description; Description) { }

dataitem(Location; Location)
//is there a way to use an onpredataitem and onaftergetrecord trigger to pull the location name?
DataItemLink = "Code" = field ("Location Code");
column(Name; Name) { }



Best Answer


  • SanderDkSanderDk Posts: 323Member
    Hi @mscalamogna
    You can on either sales invoice header or sales invoice line add a local variable for Type Record and subtype Location.

    Then onAfterGetRecord you can added code like:
    IF NOT Location.GET("Sales Invoice Line"."Location Code") THEN
    For help, do not use PM, but use forum instead, perhaps other people have the same question, or better answers.
  • mscalamognamscalamogna Posts: 3Member
    I've tried this a couple of different ways, still having trouble. Is there any way you can post what the entire trigger should look like? I am completely new to this and really struggling to grasp it... I really appreciate your help. I'm not a developer by trade... lol.
  • mscalamognamscalamogna Posts: 3Member
    WAIT. I got it. You literally did write what the entire trigger should look like :smiley:

    Thank you! Here is where I landed... seems to be working

    trigger OnAfterGetRecord()
    slsLocation: Record Location;
    if not slsLocation.Get("Sales Line"."Location Code") then
    clear(slsLocation) else
    locationName := slsLocation.Name

Sign In or Register to comment.