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

How to clear direct unit cost field after selecting item no. in purchase quote subform

(0) ShareShare
ReportReport
Posted on by 130

Hi all,

We reuse items for some generic transactions, and as a result, the last direct cost always populates as direct unit cost in the purchase quote subform (purchase line).

I would like to do the following:

  • after a user selects a no. in a line in the purchase quote subform
  • execute a trigger that evaluates the item.type for item.type::Non-inventory
  • Sets the item last direct cost to 0.00, and sets the purchase line direct unit cost to 0.00

I have tried several code approaches, but I can't even get my code to hit a breakpoint, which gives me the suspicion I'm not even writing code in the right place 

Please see some examples below....thank you in advance

BELOW IS WRITTEN IN: modify(No.) IN PURCHASE QUOTE SUBFORM PAGE EXTENSION

pastedimage1673077761550v1.png

BELOW IS WRITTEN IN: modify(No.) IN ITEM LOOKUP PAGE EXTENSION

pastedimage1673077960838v2.png

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

    You can use the following code

    [EventSubscriber(ObjectType::Table, Database::"Purchase Line", 'OnAfterUpdateDirectUnitCost', '', false, false)]

       local procedure OnAfterUpdateDirectUnitCost(var PurchLine: Record "Purchase Line"; xPurchLine: Record "Purchase Line"; CalledByFieldNo: Integer; CurrFieldNo: Integer);

       var

           Item: Record Item;

       begin

           if PurchLine."Document Type" = PurchLine."Document Type"::Quote then

               if PurchLine.Type = PurchLine.Type::Item then begin

                   Item.Get(PurchLine."No.");

                   if Item.Type = Item.Type::"Non-Inventory" then begin

                       item."Last Direct Cost" := 0;

                       PurchLine.Validate("Direct Unit Cost", 0);

                       Item.Modify();

                   end;

               end;

       end;

  • SammySevens Profile Picture
    130 on at

    Hi Mohana,

    This is a fantastic answer and works perfectly. It is robust and well thought out....thank you!

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

#2
YUN ZHU Profile Picture

YUN ZHU 1,103 Super User 2026 Season 1

#3
Kamal Khakhkhar Profile Picture

Kamal Khakhkhar 695

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans