Convert a sales quotation to a sales order in X++ D365
To convert a sales quotation to a sales order in X++, you typically
create a new sales order header and lines based on the information from the
existing sales quotation. Here's an example X++ code snippet:
static void ConvertQuotationToSalesOrder(Args
_args)
{
SalesQuotationTable
salesQuotationTable;
SalesQuotationLine
salesQuotationLine;
SalesTable salesTable;
SalesLine salesLine;
ttsBegin;
// Replace
'YourQuotationId' with the actual quotation ID
salesQuotationTable =
SalesQuotationTable::find('YourQuotationId');
if
(salesQuotationTable)
{
//
Create a new sales order header
salesTable.clear();
salesTable.initValue();
salesTable.CustAccount = salesQuotationTable.CustAccount;
salesTable.CurrencyCode = salesQuotationTable.CurrencyCode;
salesTable.insert();
//
Retrieve quotation lines and create sales order lines
while
select * from salesQuotationLine
where salesQuotationLine.SalesQuotationId ==
salesQuotationTable.SalesQuotationId
{
salesLine.clear();
salesLine.initValue();
salesLine.SalesId = salesTable.SalesId;
salesLine.ItemId = salesQuotationLine.ItemId;
salesLine.ItemName = salesQuotationLine.ItemName;
salesLine.LineAmount = salesQuotationLine.LineAmount;
salesLine.SalesPrice = salesQuotationLine.SalesPrice;
salesLine.SalesQty = salesQuotationLine.SalesQty;
salesLine.insert();
}
//
Update quotation status or perform any other required actions
salesQuotationTable.updateStatus(SalesQuotationStatus::Confirmed);
ttsCommit;
info("Sales order created successfully.");
}
else
{
warning("Quotation not found.");
}
}
Make sure to replace 'YourQuotationId' with the actual quotation ID you want
to convert. This code assumes that the SalesQuotationTable and
SalesQuotationLine tables are used for quotations and the SalesTable and
SalesLine tables are used for orders. Adjust the field names and relationships
based on your data model. Additionally, you may need to include logic to handle
inventory, pricing, and other business rules depending on your specific
requirements.
Comments