Hi, Readers.
Recently I was asked an interesting question, can we specify the No. Series when creating a Sales Order (Make Order) from Sales Quote.
As you might know, in Business Central, you create a sales quote to record your offer to a customer or a prospect to sell certain products on certain delivery and payment terms. You can send the sales quote to the customer to communicate the offer. When the customer accepts the quote, you convert the sales quote to a sales invoice or a sales order in which you process the sale. For example, choose Make Order on the Sales Quote page.

Choose Yes.

The quote has been converted to order 101021.


This is a standard feature. As for the automatically generated Sales Order number, the default number in the No. Series is obtained.


What happens if no default number is set? Let’s look at another example:

When you click Maker Order, the following error message will appear. Therefore, the Default Nos. must be Enabled.
It is not possible to assign numbers automatically. If you want the program to assign numbers automatically, please activate Default Nos. in No. Series S-ORD.

The same error is also prompted when manually creating an order.

However, on the Sales Order page, we can select … after No. and then select No. Series to create an order, but this cannot be done when making an order on the Sales Quote.

PS: Dynamics 365 Business Central: No. Series Relationships (Multiple Number Series)


PS: On sales, purchase, transfer, and service documents, and on all cards, the No. field can be filled in automatically from a predefined number series, or you can add it manually. The No. field can be filled in three ways:
- If only one number series for the type of document or card exists, and the Default Nos. field is selected and the Manual Nos. field isn’t selected for that number series, then the field is automatically filled with the next number in the series.
- If you have more than one number series for a type of document or card, and the Default Nos. checkbox isn’t selected for the assigned number series, the No. field displays, and you can go to the No. Series page and select the number series you want to use. The next number in the series is then inserted in the No. field.
- If you don’t have a number series for a type of document or card, or if the Manual Nos. field is selected for the number series, the No. field displays and you must enter a number manually. You can enter up to 20 alphanumeric characters.
More details: Behavior of the No. field on documents and cards
In standard code: codeunit 1400 DocumentNoVisibility -> procedure ForceShowNoSeriesForDocNo

So can we specify the No. Series when creating a Sales Order (Make Order) from Sales Quote just like in Sales Order? Yes, it can be done. But it requires some customization.
This time we mainly use the following event.
codeunit 86 “Sales-Quote to Order” -> local procedure CreateSalesHeader -> OnCreateSalesHeaderOnBeforeSalesOrderLineLockTable

Let’s look at two simple requirements.
1. Customers need to manually number the order. When creating an order, the number in Your Reference field will be automatically used as the order number.




Test video:
Source code: Github (Please note that the source code is for reference only, you can improve it according to your own needs)
codeunit 50112 SalesQuoteToOrderHandler
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Quote to Order", OnCreateSalesHeaderOnBeforeSalesOrderLineLockTable, '', false, false)]
local procedure "SQtoOrder_OnCreateSalesHeaderOnBeforeSalesOrderLineLockTable"(var SalesHeaderOrder: Record "Sales Header"; var SalesHeaderQuote: Record "Sales Header")
begin
SalesHeaderOrder."No." := SalesHeaderQuote."Your Reference";
end;
}
2. Specify the No. Series when creating a Sales Order (Make Order) from Sales Quote just like in Sales Order
We can do this with the following standard function.
codeunit 310 “No. Series” -> LookupRelatedNoSeries: Opens a page to select a No. Series related to the OriginalNoSeriesCode (including the OriginalNoSeriesCode).

For example,

Test:





Test video:
Source code: Github (Please note that the source code is for reference only, you can improve it according to your own needs)
codeunit 50112 SalesQuoteToOrderHandler
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Quote to Order", OnCreateSalesHeaderOnBeforeSalesOrderLineLockTable, '', false, false)]
local procedure "SQtoOrder_OnCreateSalesHeaderOnBeforeSalesOrderLineLockTable"(var SalesHeaderOrder: Record "Sales Header")
var
NoSeries: Codeunit "No. Series";
NewNoSeriesCode: Code[20];
SalesSetup: Record "Sales & Receivables Setup";
begin
NewNoSeriesCode := '';
SalesSetup.Get();
SalesSetup.TestField("Order Nos.");
if NoSeries.LookupRelatedNoSeries(SalesSetup."Order Nos.", NewNoSeriesCode) then
SalesHeaderOrder."No." := NoSeries.GetNextNo(NewNoSeriesCode);
end;
}
PS: Please do not use OnBeforeInsertSalesOrderHeader event, it will cause the following error


An error occurred and the transaction is stopped. Contact your administrator or partner for further assistance.

Error message:
An error occurred and the transaction is stopped. Contact your administrator or partner for further assistance.
The following AL methods are limited during write transactions because one or more tables will be locked: Form.RunModal, Codeunit.Run, Report.RunModal, XmlPort.RunModal.
Form.RunModal is not allowed in write transactions.

Great, give it a try!!!😁
PS:
1. Dynamics 365 Business Central: How to combine the No. Series with the date (No Customization)
2. Dynamics 365 Business Central: Can we create a Sales Quote without a customer and items?
END
Hope this will help.
Thanks for reading.
ZHU
コメント