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

Line Amount trigger not working on Purchase Invoice

(0) ShareShare
ReportReport
Posted on by

Dear All,

I have an issue with a trigger whereby, when I enter quantity and unit cost the total amount is calculated and put in Line Amount field ,a trigger should run my function and check the amount in Line Amount field, compare it with another amount am having in a custom field and give an alert or a message.


I have used Modify("Line Amount") as per the below and I called my function through a trigger but unfortunately there is no alert. It seems like the trigger is not running the function.

  Modify("Line Amount")
    {
       Trigger OnAfterValidate()
       Begin
         CheckBudgetOveruns();
       End;
      
    }

My questions is, is this the best trigger?

I have the same question (0)
  • TanzeelurRehman Profile Picture
    75 on at

    if you just assign Line Amount := somevalue, the OnBeforeValidate and OnAfterValidate trigger won't fire, I think the standard function only assigns value to line amount not using the validate function. you need to add one more event to rescue, that is OnAfterValidate of unit cost where you need to forcefully fire the validate trigger for line amount like 

    Rec.Validate("Line Amount", Rec.Line Amount);

    It will fire both OnBefore and OnAfterValidate triggers.

  • Romryan Profile Picture
    on at

    TanzeelurRehman,

    Thanks for response. Are you saying that I should the code as below?

    Modify("unit cost")

       {

          Trigger OnAfterValidate()

          Begin

            Rec.Validate("Line Amount", Rec.Line Amount);

            CheckBudgetOveruns();

          End;

       }

  • Verified answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    In the purchase line table there is an event called OnAfterCalcLineAmount, subscribe to that event and then add your condition.

  • Verified answer
    TanzeelurRehman Profile Picture
    75 on at

    The answer provided by Suresh is perfect one. Subscribe to the event OnAfterCalcLineAmountsubscribe.

    The code should be look like this

    [EventSubscriber(ObjectType::Table, Database::"Purchase Line", 'OnAfterCalcLineAmount', '', false, false)]
    local procedure OnAfterCalcLineAmount(var PurchaseLine: Record "Purchase Line"; var LineAmount: Decimal);
    begin
         CheckBudgetOveruns(); 
    end;

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,010

#2
Jainam M. Kothari Profile Picture

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

#3
YUN ZHU Profile Picture

YUN ZHU 1,085 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans