Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Create purchase order direct delivery from sales order(by the CSV file)

Posted on by 237

Dear all,

I code to create the purchase order direct delivery from sales order by reading parameter from CSV file and create purchase order X++.

But when I set the purchase price for Price line in the Purchase order line from the CSV file, but it does not work.

It's always getting purchase price from the item master(Released product master >> Purchase tab >> Price).

Please advise me how to update source code to get Price from CSV file?

PurchAutoCreate purchAutoCreate;
TmpPurchLinePrice tplP;
VendAccount prevVendAccount;
SalesTable salesTableLocal;
SalesLine salesLineLocal;
InventTable inventTable;
LineNum lineNumber = 0;
PurchCreateFromSalesOrder purchCreateFromSalesOrder;
;

try
{
ttsbegin;
while select salesLineLocal
order by inventTable.PrimaryVendorId
where salesLineLocal.SalesId == ‘00018_036’
join inventTable
where inventTable.ItemId == salesLineLocal.ItemId
{
if (prevVendAccount && prevVendAccount != inventTable.PrimaryVendorId)
{
purchAutoCreate = PurchAutoCreate::construct(tplP, purchCreateFromSalesOrder);
purchAutoCreate.create();
delete_from tplP;
lineNumber = 0;
}

salesTableLocal = salesLineLocal.salesTable();
purchCreateFromSalesOrder = PurchCreateFromSalesOrder::construct();
purchCreateFromSalesOrder.callerRecord(salesTableLocal);

tplP.clear();
lineNumber += 1;
tplP.SalesId = #fromCSV;
tplP.LineNum = #fromCSV;
tplP.SalesLineRefRecId = salesLineLocal.RecId;
tplP.AccountNum = #fromCSV;

tplP.ItemId = #fromCSV
tplP.InventDimId = salesLineLocal.InventDimId;

tplP.Included = NoYes::Yes;

tplP.PurchQty = #fromCSV
tplP.QtyOrdered = #fromCSV

tplP.PurchUnit = salesLineLocal.SalesUnit;
tplP.LineAmount = ???;

tplP.LineDisc = salesLineLocal.LineDisc;
tplP.LinePercent = salesLineLocal.LinePercent;
tplP.MultiLineDisc = salesLineLocal.MultiLnDisc;
tplP.MultiLinePercent = salesLineLocal.MultiLnPercent;

tplP.Price = #fromCSV;
tplP.PriceUnit = salesLineLocal.PriceUnit;
tplP.CurrencyCode = #fromCSV;

tplP.Markup = salesLineLocal.SalesMarkup;

tplP.insert();

prevVendAccount = tplP.AccountNum;
}

if (prevVendAccount)
{
purchAutoCreate = PurchAutoCreate::construct(tplP, purchCreateFromSalesOrder);
purchAutoCreate.create();
}
ttscommit;
}
catch (Exception::Error)
{
ttsabort;
}
}



Thanks in advance!!!

*This post is locked for comments

  • Shinji Hoang Profile Picture
    Shinji Hoang 237 on at
    RE: Create purchase order direct delivery from sales order(by the CSV file)

    Dear Ludwig,

    Thank you for your response.

    I received a request from end-user.

    When they create direct delivery from sales order. they must be select line by line to create PO(direct delivery).

    So they want to import the list of sales order and create direct delivery automatically base on CSV file contains.

    Best regards,

    Kaneko

  • Ludwig Reinhard Profile Picture
    Ludwig Reinhard Microsoft Employee on at
    RE: Create purchase order direct delivery from sales order(by the CSV file)

    Hello Sacramento,

    I cannot help you with your code but wonder why you want to create purchase orders from a CSV file?

    On first sight this sounds strange especially when you deal with mass data (POs, vendors, items, etc.)

    Why is it that you need to do that?

    Best regards,

    Ludwig

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create purchase order direct delivery from sales order(by the CSV file)

    Hi,

    I think you should use PurchAutoCreate_Sales instead of PurchAutoCreate

    if you look into PurchAutoCreate_Sales.CreateLine(), you will see pricing logic there (to get the price from tmpPurchLinePrice)

    Cheers

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans