Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

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

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

  • SammySevens Profile Picture
    SammySevens 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!

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,077 Super User 2024 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;

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,113 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,918 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans