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

Notifications

Announcements

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
    Olister Rumao Profile Picture
    3,967 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.

  • Suggested answer
    Mohana Yadav Profile Picture
    61,025 Super User 2025 Season 2 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.

  • 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,025 Super User 2025 Season 2 on at

    you have to use Sales Line, No. field

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

News and Announcements

Season of Giving Solutions is Here!

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 1,476

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 789 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 719 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans