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...
Suggested Answer

Create Purchase Order from Sales Order - Default Unit Costs to Zero

(7) ShareShare
ReportReport
Posted on by 683
 
Request is when using the Create Purchase Document from a Sales Order, the Unit Costs that populate are all zero.  The Unit Costs come from the Last Direct Cost of the Item, which I have entertained setting all to zero in the above thread.
 
I have added code to Page 1328 (Purch. Order From Sales Order) so that when the Quantity is entered/updated, it sets the Line Unit Cost to zero.
 
However, if the Vendor field (which is the Name, not No.) is selected/changed after the Quantity is entered, the Unit Cost is changed back to the Item.LastDirectCost.
 
Looking for the correct coding to change the Unit Cost to zero when the Vendor is updated.
I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    95,729 Super User 2025 Season 2 on at
    Hi, Sorry, I haven't tested it in detail. You can try 1 or 2 below to see if it meets your needs.
     
    Thanks
    ZHU
  • ME-31032107-0 Profile Picture
    683 on at
     
    This will not work, as Page 1328 is based on the table "Requisition Line".  I tried it on that table, and it did not work.  I need to be able to change the Unit Cost when the Vendor is selected in the Page.  Vendor is a lookup field and returns the Name (not the No.), and I can't seem to get the validation to work because the Vendor Name is not in the Requisition Line table.
  • Suggested answer
    Ramesh Kumar Profile Picture
    7,529 Super User 2025 Season 2 on at
    Hi,
     
    May be below can help
     
    pageextension 50100 PurchOrderFromSalesOrderExt extends "Purch. Order From Sales Order"
    {
     

        trigger OnAfterValidate()
        begin
            // If you're modifying the field directly in this page, do:
            Rec.Validate("Unit Cost", 0);
        end;
        // Or better yet, use a field-level trigger if you're modifying the base table
        modify("Buy-from Vendor Name")
        {
            trigger OnAfterValidate()
            begin
                Rec.Validate("Unit Cost", 0);
            end;
        }
    }
     
     
    Note: If "Buy-from Vendor Name" is a calculated or flow field from the Vendor table (based on "Buy-from Vendor No."), then it's better to use "Buy-from Vendor No." instead, as this is the actual key that drives vendor data
     
    Thanks
    Ramesh
  • Gerardo Rentería García Profile Picture
    25,236 Most Valuable Professional on at
    Hi
    Make sure there is no additional logic in subsequent events that recalculates the cost (for example, in OnInsert or OnModify).
    or try again by entering the code in the Buy-from Vendor No. field.
    Best
    Gr
  • Suggested answer
    Jainam M. Kothari Profile Picture
    15,639 Super User 2025 Season 2 on at
  • ME-31032107-0 Profile Picture
    683 on at
    Below is the code from Page 1328 for the Vendor field.  There is no "Buy-from Vendor No." on the page.  I cannot figure out how to validate the Direct Unit Cost field when the Vendor field is entered or changed.
     
                    field(Vendor; VendorName)
                    {
                        ApplicationArea = Suite;
                        Caption = 'Vendor';
                        ShowMandatory = true;
                        Style = Subordinate;
                        StyleExpr = Rec.Quantity = 0;
                        ToolTip = 'Specifies the vendor who will ship the items in the purchase order.';
                        trigger OnLookup(var Text: Text): Boolean
                        var
                            Vendor: Record Vendor;
                        begin
                            Rec.TestField("Replenishment System", Rec."Replenishment System"::Purchase);
                            if not Rec.LookupVendor(Vendor, false) then
                                exit;
                            Rec.SetCurrFieldNo(Rec.FieldNo("Supply From"));
                            Rec.Validate(Rec."Supply From", Vendor."No.");
                            VendorName := Vendor.Name;
                        end;
                        trigger OnValidate()
                        var
                            Vendor: Record Vendor;
                        begin
                            Rec.TestField("Replenishment System", Rec."Replenishment System"::Purchase);
                            Rec.SetCurrFieldNo(Rec.FieldNo("Supply From"));
                            Rec.Validate(Rec."Supply From", Vendor.GetVendorNo(VendorName));
                            if Vendor.Get(Rec."Supply From") then
                                VendorName := Vendor.Name
                            else
                                VendorName := Rec."Supply From";
                        end;
                    }
  • ME-31032107-0 Profile Picture
    683 on at
    What I wound up doing (which I am not sure is the best way to handle it) was to create a Table Extension on the "Requisition Line" table to set the cost to zero when changing the "Supply From" Vendor field.  This accomplishes what I need.
     
    tableextension 50105 RequisitionLineTableExt extends "Requisition Line"
    {
        fields
        {
            modify("Supply From")
            {
                trigger OnAfterValidate()
                begin
                    Validate("Direct Unit Cost", 0);
                end;
            }
        }
    }
  • Suggested answer
    Sohail Ahmed Profile Picture
    11,150 Super User 2025 Season 2 on at
    The system updates the Unit Cost based on the Last Direct Cost when the Vendor is selected or changed, which overrides your custom logic.
     
    ✅ To keep Unit Cost as zero, you’ll need to extend the OnAfterValidate trigger on the Vendor field (on page 1328 or table 39) and reset the Unit Cost there too.
     
    That way, even when Vendor changes, your logic forces the cost to stay at 0.
     
    ✅ Mark this answer as verified if it helps 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…

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 2,135

#2
YUN ZHU Profile Picture

YUN ZHU 733 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 612

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans