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

Business Central - AL Code

(0) ShareShare
ReportReport
Posted on by 44

Hi All,

I'm trying to write some code for the following;

I need the field "Qty Per Unit of Measure"  from the "Item Unit Of Measure " table to be produced on the Purchase order report.

I created the Table , page and report extension.

The issue I'm having is, If for example the Unit of Measure Code for the Item is "Box", the table extension i created, 'Qty per UoM" doesn't automatically populate that field, i can either select from the drop down, or type it in manually.

It shows on the report just fine. What i need it for this field to be populated once the Unit of Measure is selected and ideally be hidden on the Purchase Order page.

Here's my code - I tried a few triggers but they didn't work so i removed them.

Any help would be greatly appreciated!

tableextension 50128 "Qty Per UoM2" extends "Purchase Line"
{
    fields
    {
        field(50128; "Qty Per UoM2"; Decimal)
        {

            Caption = 'Qty Per UoM2';
            TableRelation = "Item Unit of Measure"."Qty. per Unit of Measure"
where(Code = field("Unit of Measure Code"));
            ValidateTableRelation = false;

        }
    }
}
I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    98,498 Super User 2026 Season 1 on at

    Hi, this is because you need to add some code to the validate trigger of the Unit of Measure Code.

    For example.

    tableextension 50128 "Qty Per UoM2" extends "Purchase Line"
    
    {
        fields
        {
            modify("Unit of Measure")
            {
                trigger OnAfterValidate()
                var
                    ItemUnitOfMeasure: Record "Item Unit of Measure";
                begin
                    if Rec.Type = Rec.Type::Item then
                        if ItemUnitOfMeasure.Get(Rec."No.") then
                            Rec."Qty Per UoM2" := ItemUnitOfMeasure."Qty. per Unit of Measure";
                end;
            }
    
            field(50128; "Qty Per UoM2"; Decimal)
    
            {
                Caption = 'Qty Per UoM2';
                TableRelation = "Item Unit of Measure"."Qty. per Unit of Measure" where(Code = field("Unit of Measure Code"));
                ValidateTableRelation = false;
                DataClassification = CustomerContent;
            }
    
        }
    
    }

    Hope this helps.

    Thanks.

    ZHU

  • rajivsewsarran Profile Picture
    44 on at

    Hi ZHU,

    Thanks for your response.

    I tried this, but still not getting the "Qty Per UoM2" field to populate.

  • Suggested answer
    Alok.kulshreshtha Profile Picture
    934 on at

    Hi,

    In Zhu's code make below correction  and rest all ok. with this change it should work

    if ItemUnitOfMeasure.Get(Rec."No.",Rec."Unit Of Measure Code") then

    Regads,

    Alok Kulshreshtha

  • rajivsewsarran Profile Picture
    44 on at

    Hi Alok,

    Thanks for your response.

    This is my code now , i still can't get  it to work. Apologies i'm very new to this.

    tableextension 50108 "Quantity Per UoM" extends "Purchase Line"

    {

       fields

       {

           modify("Unit of Measure")

           {

               trigger OnAfterValidate()

               var

                   ItemUnitOfMeasure: Record "Item Unit of Measure";

               begin

                   if ItemUnitOfMeasure.Get(Rec."No.", Rec."Unit Of Measure Code") then

                       if ItemUnitOfMeasure.Get(Rec."No.") then

                           Rec."Quantity Per UoM" := ItemUnitOfMeasure."Qty. per Unit of Measure";

               end;

           }

           field(50108; "Quantity Per UoM"; Decimal)

           {

               Caption = 'Quantity Per UoM';

               TableRelation = "Item Unit of Measure"."Qty. per Unit of Measure" where(Code = field("Unit of Measure Code"));

               ValidateTableRelation = false;

               DataClassification = CustomerContent;

           }

       }

    }

  • Verified answer
    YUN ZHU Profile Picture
    98,498 Super User 2026 Season 1 on at

    Sorry, I missed a primary key, and there is actually another mistake.

    I checked on the screen this time, try the code below.

    tableextension 50128 "Qty Per UoM2" extends "Purchase Line"
    {
        fields
        {
            modify("Unit of Measure Code")
            {
                trigger OnAfterValidate()
                var
                    ItemUnitOfMeasure: Record "Item Unit of Measure";
                begin
                    if Rec.Type = Rec.Type::Item then
                        if ItemUnitOfMeasure.Get(Rec."No.", Rec."Unit of Measure Code") then
                            Rec."Qty Per UoM2" := ItemUnitOfMeasure."Qty. per Unit of Measure";
                end;
            }
    
            field(50128; "Qty Per UoM2"; Decimal)
    
            {
                Caption = 'Qty Per UoM2';
                TableRelation = "Item Unit of Measure"."Qty. per Unit of Measure" where(Code = field("Unit of Measure Code"));
                ValidateTableRelation = false;
                DataClassification = CustomerContent;
            }
        }
    }

    pastedimage1652843135266v1.png

    Thanks.

    ZHU

  • rajivsewsarran Profile Picture
    44 on at

    Hi ZHU,

    Thanks for all your help, this now works.

    Really appreciate it!

    Regards

    Rajiv

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,850 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,084 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 959 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans