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

OnAfterValidate Event not working on standard field - AL Code

(1) ShareShare
ReportReport
Posted on by 3,247
Hi Everyone
I'm trying to calculate Item Card custom unit price based on unit cost field. When unit cost is updated for example purchase doc I want o update the custom field unit price however it is not working. Same code woks when placed on the profitpercentage2 field and update from item card
 
        modify("Unit Cost")
        {
            trigger OnAfterValidate()
            var
 
            begin
                if ProfitPercentage2 < 100 then begin
                    GetGLSetup();
                    UnitPrice2 :=
                      Round(
                        ("Unit Cost" * ((100 + ProfitPercentage2) / 100)) *
                        (1 + CalcVAT()),
                        GLSetup."Unit-Amount Rounding Precision");
                end;
            end;
        }
I have the same question (0)
  • Verified answer
    Yi Yong Profile Picture
    2,555 Super User 2025 Season 2 on at
    Hello,
     
    You can't do that because the standard codeunit does not use Validate function when updating the Item's Unit Cost.
    They assigned the Unit Cost instead.
     
     
    Try using the below event for your purpose.
    [EventSubscriber(ObjectType::Codeunit, Codeunit::ItemCostManagement, OnAfterUpdateUnitCost, '', false, false)]
    local procedure ItemCostManagement_OnAfterUpdateUnitCost(var Item: Record Item; CalledByFieldNo: Integer)
    begin
    // Insert your code here
    end;
    You can look into Codeunit::ItemCostManagement for other events to subscribe to.

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 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans