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...
Suggested Answer

Triggering OnInsert of a Subform

(0) ShareShare
ReportReport
Posted on by 358

I have extended an Item Table and Item Card Page with an Integer type field called Purchase Price.
I have to have this be shown on Subform of Sales Order. I added the field on the Subform after extending Sales Line table with the same field Purchase Price and have written the code;

trigger OnValidate()
            var
                ItemContainer: Record Item;
            begin
                IF ItemContainer.GET(Rec."No.") then BEGIN
                    "Purchase Price" := ItemContainer."Purchase Price";
                    ItemContainer.Modify();
                END;
            end;

Once at the subform I select this item, I want to just how Description and other fields get filled automatically; to get Purchase Price get populated as well. Right now only when the Purchase Price field is validated it brings in the value or else shows 0.

What trigger can I write the code in so that once an Item is selected by the user at Subform, just how other item related fields are filled automatically in one go, so does my Purchase Price?

I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    61,172 Super User 2026 Season 1 on at

    you have to use Sales Line, No. field

  • mysamza Profile Picture
    358 on at

    In extended page and table can't access the standard field's onvalidate triggers. I am sorry but I believe I don't get what are you suggesting?

  • Suggested answer
    Mohana Yadav Profile Picture
    61,172 Super User 2026 Season 1 on at

    you have to create a page and event subscriber of OnAftervalidate trigger of sales line, No. field.

    or any publisher available in No. OnValidate trigger.

  • Suggested answer
    Olister Rumao Profile Picture
    4,009 on at

    Hi Mesam,

    You can use this.

    After you set the Purchase Price field on Item Table, you will need to create a field on Sales Lines say Purchase Price using extension.

    On the Sales Line Table, use the following code to set the Purchase Price on Sales Line after selection of the Item.

    modify("No.")

    {

    trigger OnAfterValidate()

    var

    Rec_Items: Record Item;

    begin

    Rec_Items.Get(Rec."No.");

    Rec."Purchase Price" := Rec_Items."Purchase Price";

    end;

    }

    Please do not copy paste this code, instead type it so you get the variable,field names correctly.

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 2,161 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,046 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 932 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans