Purchase Order Short Closed Feature in BC D365:
(1) In Business Central D365 “Purchase Order Short Closed” feature is not available. But in industries the demand for this feature is mandatory.
(2) For adding the PO Short Closed feature, we will develop a small function to achieve this requirement, as shown.
(3) Create PurchaseHeader extension to add a new field “ShortClosed” as shown.
(4) After creating a new field, create a function ( it’s your choice where you want to create function. In this blog I have used a new codeunit and in that codeunit I have created a new function of PO Short Closed) as shown.
(5) After doing the above steps, call this function on the Purchase Order page by using the “Short Closed” button.
Source Code:
codeunit 50001 “Custom Functions-01” { trigger OnRun() begin end; procedure ShortClosePurchaseOrder(DocumentNo: Code[20]) var PurchaseHeader: Record “Purchase Header”; PurchaseLine: Record “Purchase Line”; begin PurchaseHeader.reset; PurchaseHeader.Setfilter(“Document Type”, ‘%1’, PurchaseHeader.”Document Type”::Order); PurchaseHeader.SetRange(“No.”, DocumentNo); if PurchaseHeader.FindFirst() then begin PurchaseLine.reset; PurchaseLine.SetFilter(“Document Type”, ‘%1’, PurchaseLine.”Document Type”::Order); PurchaseLine.Setrange(“Document No.”, DocumentNo); if PurchaseLine.FindSet() then begin repeat if PurchaseLine.”Quantity Received” <>PurchaseLine.”Quantity Invoiced” then error(‘Sales Invoice of Line No. %1 is pending’, PurchaseLine.”LIne No.”); until PurchaseLine.Next = 0; PurchaseHeader.ShortClosed := True; PurchaseHeader.Modify; end; end; end; } |