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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Displaying the Parent Item Category

(0) ShareShare
ReportReport
Posted on by 20

I am trying to display the parent item category code, along with the Item category code on the item card. I have the code mostly written out, but its not displaying the parent category code in business central, and im not sure what i am missing.

pageextension 50103 MyExtension extends "Item Card"
{
    layout
    {
        // Add changes to page layout here
        addafter("No.")
        {
            field(LegacyId; Rec.LegacyId)
            {
                ApplicationArea = All;
            }
            field(MPN; Rec.MPN)
            {
                ApplicationArea = All;
            }
            field(Model; Rec.Model)
            {
                ApplicationArea = All;
            }
            field(ItemClass; ItemClass)
            {
                Caption = 'Class';
                ApplicationArea = All;
            }

        }
        addafter(GTIN)
        {
            field(ParentCode; ParentCode)
            {
                Caption = 'Parent Category';
                ToolTip = 'Parent Category';
                ApplicationArea = All;
                Editable = false;
            }
        }
        addafter(VariantMandatoryDefaultNo)
        {
            field(Recycle; Rec.Recycle)
            {
                ApplicationArea = All;
            }
        }
    }

    actions
    {
        // Add changes to page actions here
    }
    trigger OnOpenPage()
    var
        ItemCategory: Record "Item Category";
        ParentCode: Code[20];
    begin
        ParentCode := ItemCategory."Parent Category";
        SaveRecord();
    end;

    var
        myInt: Integer;
        ItemClass: Enum ItemClass;
        ParentCode: Code[20];
}

  • Nitin Verma Profile Picture
    21,812 Moderator on at

    Try this instead of OpenPage.

    trigger OnAfterGetRecord()

       var

           ItemCategory: Record "Item Category";

           ParentCode: Code[20];

       begin

           ItemCategory.get(rec."Item Category Code");

           ParentCode := ItemCategory."Parent Category";

           SaveRecord();

       end;

  • Robert Rupp Profile Picture
    20 on at

    It did not work, but thank you for the recommendation. The code does not throw any errors

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    You can add one more filter Item no. With item category table

  • Suggested answer
    Govinda Kumar Profile Picture
    2,310 Moderator on at

    Hi,

    Looks like you're missing a filter condition in your ItemCategory buffer

        var
            ItemCategory: Record "Item Category";
            ParentCode: Code[20];
        begin
            ItemCategory.SetFilter(Code, Rec."Item Category Code");
            if (ItemCategory.Find('-')) then begin
                ParentCode := ItemCategory."Parent Category";
            end;
            SaveRecord();
        end;
               

    Also, Nitin Verma suggested adding the code in onAfterGetRecord trigger is a good practice.. add the code there instead of OnOpenPage

    Regards

  • Robert Rupp Profile Picture
    20 on at

    It still did not work, but thank you for telling me about the good practice.

  • Verified answer
    Govinda Kumar Profile Picture
    2,310 Moderator on at

    Hi Robert Rupp,
    Please don't use the ParentCode variable when modifying the field. Instead, use the field itself. Here's the corrected code.

        trigger OnAfterGetCurrRecord()
        var
            ItemCategory: Record "Item Category";
        begin
            ItemCategory.SetFilter(Code, Rec."Item Category Code");
            if (ItemCategory.Find('-')) then begin
                Rec.ParentCode := ItemCategory."Parent Category";
                Rec.Modify();
            end;
        end;

    I have tested this and can confirm that it works.
    Regards

  • Robert Rupp Profile Picture
    20 on at

    That worked thank you so much!!!!

  • Suggested answer
    Govinda Kumar Profile Picture
    2,310 Moderator on at

    Robert Rupp,

    Glad to hear that it worked.. thank you for letting me know..

    Regards

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 768 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 541 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 324 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans