web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    60,967 Super User 2025 Season 2 on at
    RE: How to clear direct unit cost field after selecting item no. in purchase quote subform

    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
    RE: How to clear direct unit cost field after selecting item no. in purchase quote subform

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 4,232

#2
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 2,863

#3
Sumit Singh Profile Picture

Sumit Singh 2,819

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans