web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Import Sales Orders through a CSV file

(0) ShareShare
ReportReport
Posted on by 587

Hi All,

I am trying to import 1000+ sales orders into AX 2009, I have a job but I cannot import multiple line sales orders. I will admit that I am not the best programmer and this is a common task that many of us has preform. Would anyone have an X++ they can share as an example to do this?

I am using the axSalesTable and axSalesLine class to do this.

Cheers

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Can you tell us why you "cannot import multiple line sales orders", please? What error do you get, or what else happens?

  • Johnkrish Profile Picture
    781 on at

    Hi,

    You can get many x++ code posts from the internet like this

    https://erpdax.wordpress.com/2014/08/20/importing-sales-order-sales-lines-from-csv-file/

    But what is the exact problem you facing/ what is the error you are getting, Otherwise share your code.

    It'll be useful to help you.

  • SergiPB Profile Picture
    587 on at

    Hi Guys,

    I had success with the link that John provided but having trouble in getting this to import multiple SOs header and lines in one file. I have a customer PO number  as the reference on the header and lines files for each SO that I need created but having trouble in creating the logic and X++.

    Any examples on importing multiple sales orders in one text file would be useful.

    Here is the job I used and had success with on importing one sales order, I need to modify this to import multiple sales orders now.

    static void MultiSalesOrdersLineImport(Args _args)

    {

    SalesTable      salesTable;

    SalesLine       salesLine;

    InventDim       inventDim;

    container       readcon,readcon1;

    NumberSeq       num;

    CommaIo         commaIo,commaIo1;

    ;

    commaIo = new CommaIo(@'C:\Users\Sergi\Desktop\importFile\Lines.txt','r');

    commaIo1 = new CommaIo(@'C:\Users\Sergi\Desktop\importFile\Header.txt','r');

    commaIo.infieldDelimiter(',');

    try

    {

    ttsbegin;

    // Order header

    salesTable.clear();

    readcon1  = commaIo1.read();

    salesTable.CustAccount = conpeek(readcon1,1);

    salesTable.InvoiceAccount = conpeek(readcon1,1);

    salesTable.CustomerRef = conpeek(readcon1,2);

    salesTable.CurrencyCode = 'USD';

    salesTable.LanguageId = 'en-us';

    num = NumberSeq::newGetNum(SalesParameters::numRefSalesId());

    salesTable.SalesId = num.num();

    salesTable.initValue();//

    salesTable.initFromCustTable();

    if (salesTable.validateWrite())

    {

    salesTable.insert();

    while(commaIo.status() == IO_Status::OK)

    {

    //Order line

    readcon = commaIo.read();

    salesLine.ItemId = conpeek(readcon,1);

    salesLine.CurrencyCode = 'USD';

    if(salesLine.ItemId == "0")

    break;

    inventDim.clear();

    inventDim.InventSiteId ='A';

    inventDim.InventLocationId = 'MAIN';

    salesLine.clear();

    salesLine.initValue();

    salesLine.initFromSalesTable(salesTable);

    salesLine.ItemId = conpeek(readcon,1);

    salesLine.initFromInventTable(InventTable::find(conpeek(readcon,1)));

    salesLine.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;

    salesLine.SalesQty = conpeek(readcon,2);

    salesLine.RemainSalesPhysical = salesLine.SalesQty;

    salesLine.SalesUnit = conpeek(readcon,3);

    salesLine.QtyOrdered = salesLine.calcQtyOrdered();

    salesLine.RemainInventPhysical = salesLine.QtyOrdered;

    salesLine.setPriceDisc(InventDim::find(salesLine.InventDimId));

    if (salesLine.validateWrite())

    {

    salesLine.insert();

    }

    else

    throw error("Order line");

    }

    }

    else

    throw error("Order header");

    ttscommit;

    }

    catch

    {

    error("Error!");

    return;

    }

    info("Done!");

    }

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    If there are multiple sales order headers and lines in 2 files, I would first just read all of the headers into a map, and all the lines into another map.

    msdn.microsoft.com/.../map.aspx

    They key would be your SO/PO number, since that must be unique for your header, and the value would be your header container.

    Also for the lines, the key might be the SO/PO number, and then the line would be added to the end of the lines container [ [Line1Values], [Line2Values], ... [LineNValues] ].

    Finally you just need to enumerate your header map, and find the corresponding line map key, and then iterate through the lines container to insert them.

    Another solution could be to use temporary tables instead of maps, you could try to use for example the Sales* or DMFSales* tables for this purpose, if you make them temporary with setTmp(), insert the values, then iterate those 2 tables to copy values from them to your final sales order/line buffers to commit them to the database.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans