web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Need help with triggers on report

(4) ShareShare
ReportReport
Posted on by 54
Hi guys
 
I'm trying to create an excel report that extracts item data from 4 tables. I'm fine with the main table "Item" but I need help with the triggers to get the data from the other tables "K3PF Color", "Item Variant" "Item Reference".
 
Any help is appreciated. 
 
report 50100 "Jons item export"
{
    ApplicationArea = All;
    Caption = 'Jons item export';
    UsageCategory = ReportsAndAnalysis;
    DefaultRenderingLayout = Jonsitemexport;
    dataset
    {
        dataitem(Item; Item)
        {
            column(Description; Description) { }
            column(ItemCategoryCode; "Item Category Code") { }
            column(K3PFBrandCode; "K3PFBrand Code") { }
            column(K3PFCollectionCode; "K3PFCollection Code") { }
            column(K3PFGenderCode; "K3PFGender Code") { }
            column(K3PFSeasonCode; "K3PFSeason Code") { }
            column(K3PFSizeRangeCode; "K3PFSize Range Code") { }
            column(LastDirectCost; "Last Direct Cost") { }
            column(No; "No.") { }
            column(colordescription; colordescription) { }
            column(vendoritemref; vendoritemref) { }
            column(variantcode; variantcode) { }
 
            trigger OnAfterGetRecord();
            var
                K3Color: Record "K3PF Color";
                ItemVariant: Record "Item Variant";
                ItemRef: Record Microsoft.Inventory.Item.Catalog."Item Reference";
 
            begin
 
                colordescription := K3color.Description;
                variantcode := ItemVariant.Code;
                vendoritemref := ItemRef."Reference No.";
 
            end;
 
        }
    }
    requestpage
    {
        layout
        {
            area(Content)
            {
                group(GroupName)
                {
                }
            }
        }
        actions
        {
            area(Processing)
            {
            }
        }
    }
    rendering
    {
        Layout(Jonsitemexport)
        {
            type = Excel;
            LayoutFile = 'Jonsitemexport.xlsx';
        }
    }
    var
        colordescription: Text[50];
        vendoritemref: Text[50];
        variantcode: Text[50];
 
}
I have the same question (0)
  • Verified answer
    Kamal Khakhkhar Profile Picture
    1,282 on at
    Hii there,
    As per requirement you need to reset the table. Before use it also clear the value then apply setrange as per your filter/requirement. I am giving sample so you can understand (for your onaftergetrecord() trigger)
    Clear(Colordescription);
    K3color.reset();
    K3color.setrange(filters);
    If k3color.findfirst() then begin
    Colordescription:=k3color.description;
    As per above sample you can get. Written same for other.
    If you found your reference please make it answered.
    Thank You.
    Kamal Khakhkhar
  • Verified answer
    Steven Renders Profile Picture
    5,672 Moderator on at
    Terribly sorry, but if you do not know how to write AL code to get data from the related tables, you should not be developing the report, imho.
     
    Here's some help:
  • CD-14021014-0 Profile Picture
    54 on at
    It's this part I get stuck on
     
    K3color.setrange(filters);
     
    Could you explain?
  • Suggested answer
    Suresh Kulla Profile Picture
    50,245 Super User 2025 Season 2 on at
    For you to export the data first you need to retrieve the record, in your case you need to apply filters on K3Color record by using SetRange on the Item No. field on the Color and once retrieved you can export. 
     
    Ex:
    K3Color.Reset();
    K3Color.SetRange("Item No.",Item.Color);
    if k3Color.FindSet then 
     
  • Verified answer
    YUN ZHU Profile Picture
    95,729 Super User 2025 Season 2 on at
    Or you can add another dataitem - "K3PF Color" and associate it through the field. This way you can get the data without a trigger.
    The following is an example of associating sales header with sales line.
    report 1305 "Standard Sales - Order Conf."
     
    Hope the following helps.
    Thanks.
    ZHU
  • CD-14021014-0 Profile Picture
    54 on at
    Thanks Guys,
     
    I went with Data item links and that works nicely.
     
    Cheers

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans