X++ code to create Direct Delivery Purchase order in D365FO
X++ code to create Direct Delivery Purchase order in D365FO
class
DirectDeliveryPO
{
///
<summary>
/// Runs the
class with the specified arguments.
///
</summary>
/// <param
name = “_args”>The specified arguments.</param>
public static
void main(Args _args)
{
PurchAutoCreate
purchAutoCreate;
PurchCreateFromSalesOrder
purchCreateFromSalesOrder;
TmpPurchLinePrice
tmpPurchLinePrice;
SalesTable
salesTable;
SalesLine
salesLine;
InventTable
inventTable;
VendAccount
prevVendAccount;
LineNum lineNum
= 0;
SalesId salesId
= ‘SO000081’;
str curCompany =
curExt();
try
{
ttsbegin;
while select
salesLine
order by
inventTable.PrimaryVendorId
where
salesLine.SalesId == salesId
join inventTable
where
inventTable.ItemId == salesLine.ItemId
{
if
(prevVendAccount && prevVendAccount != inventTable.PrimaryVendorId)
{
purchAutoCreate
= PurchAutoCreate::construct(tmpPurchLinePrice, purchCreateFromSalesOrder);
purchAutoCreate.create();
delete_from
tmpPurchLinePrice;
lineNum = 0;
}
salesTable =
salesLine.salesTable();
purchCreateFromSalesOrder
= PurchCreateFromSalesOrder::construct();
purchCreateFromSalesOrder.parmCallerRecord(salesTable);
purchCreateFromSalesOrder.parmTransferAddress(true);
purchCreateFromSalesOrder.parmSalesTable(salesTable);
purchCreateFromSalesOrder.parmSalesLine(salesLine);
tmpPurchLinePrice.clear();
lineNum += 1;
tmpPurchLinePrice.SalesId
= salesLine.SalesId;
tmpPurchLinePrice.LineNum
= lineNum;
tmpPurchLinePrice.SalesLineRefRecId
= salesLine.RecId;
tmpPurchLinePrice.AccountNum
= inventTable.PrimaryVendorId;
tmpPurchLinePrice.ItemId
= salesLine.ItemId;
tmpPurchLinePrice.InventDimId
= salesLine.InventDimId;
tmpPurchLinePrice.Included
= NoYes::Yes;
tmpPurchLinePrice.PurchQty
= salesLine.SalesQty;
tmpPurchLinePrice.QtyOrdered
= salesLine.QtyOrdered;
tmpPurchLinePrice.PurchUnit
= salesLine.SalesUnit;
tmpPurchLinePrice.LineAmount
= salesLine.LineAmount;
tmpPurchLinePrice.lineDisc
= salesLine.LineDisc;
tmpPurchLinePrice.LinePercent
= salesLine.LinePercent;
tmpPurchLinePrice.MultiLineDisc
= salesLine.MultiLnDisc;
tmpPurchLinePrice.MultiLinePercent
= salesLine.MultiLnPercent;
tmpPurchLinePrice.Price
= salesLine.PriceUnit;
tmpPurchLinePrice.CurrencyCode
= salesLine.CurrencyCode;
tmpPurchLinePrice.Markup
= salesLine.SalesMarkup;
tmpPurchLinePrice.insert();
prevVendAccount
= tmpPurchLinePrice.AccountNum;
}
if
(prevVendAccount)
{
purchAutoCreate
= PurchAutoCreate::construct(tmpPurchLinePrice, purchCreateFromSalesOrder);
purchAutoCreate.create();
}
ttscommit;
Info(‘Direct
Delivery PO Created’);
}
catch
(Exception::Error)
{
ttsabort;
Info(‘Direct
Delivery PO Failed’);
}
}
}
- Get link
- X
- Other Apps
Comments
Post a Comment