Sales Order Short Closed Feature in BC D365:
(1) In Business Central D365 “Sales Order Short Closed” feature is not available. But in industries the demand for this feature is mandatory.
(2) For adding the SO Short Closed feature, we will develop a small function to achieve this requirement, as shown.
(3) Create a SalesHeader 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 SO Short Closed) as shown.
(5) After doing the above steps, call this function on the Sales Order page by using the “Short Closed” button.
Source Code:
codeunit 50001 “Custom Functions-01” { trigger OnRun() begin end; procedure ShortCloseSalesOrder(DocumentNo: Code[20]) var SalesHeader: Record “Sales Header”; SalesLine: Record “Sales Line”; begin SalesHeader.reset; SalesHeader.Setfilter(“Document Type”, ‘%1’, SalesHeader.”Document Type”::Order); SalesHeader.SetRange(“No.”, DocumentNo); if SalesHeader.FindFirst() then begin SalesLine.reset; SalesLine.SetFilter(“Document Type”, ‘%1’, SalesLine.”Document Type”::Order); SalesLine.Setrange(“Document No.”, DocumentNo); if SalesLine.FindSet() then begin repeat if SalesLine.”Quantity Shipped” <>SalesLine.”Quantity Invoiced” then error(‘Sales Invoice of Line No. %1 is pending’, SalesLine.”LIne No.”); until SalesLine.Next = 0; SalesHeader.ShortClosed := True; SalesHeader.Modify; end; end; end; } |