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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Code to manually import purchase orders from excel

(0) ShareShare
ReportReport
Posted on by 535

Hi experts,

I want to import purchase order (Header and line) from excel to AX Tables(PurchTable & PurchLine table) in AX 2012. I want a code to import purchase order details to tables. Help me, guys. 

Advance in Thanks and regards,

Vignesh

*This post is locked for comments

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

    Why do you want to write code if AX already has such a feature? Is there are any reason why you can't use the Data Import Export Framework?

  • Vignesh R Profile Picture
    535 on at

    Hi Martin,

    It's requirement to write a job for import purchase order from excel in ax 2012. Refer me a link to get a code .

    Regards,

    Vignesh

  • Verified answer
    startax Profile Picture
    1,845 on at

    Hi Vignesh ,

    There are multiple example available that create PO from X++ . You just use that peace of code and assign the variable from excel instead of hard code value .

    You can try below link to create PO

    ax2012xppdataimport.blogspot.com/.../microsoft-dynamics-ax-2012-xpp-purchase.html

    For Excel import you can also find example..

    static void InsertRecords(Args _args)

    {

        SysExcelApplication application;

        SysExcelWorkbooks workbooks;

        SysExcelWorkbook workbook;

        SysExcelWorksheets worksheets;

        SysExcelWorksheet worksheet;

        SysExcelCells cells;

        COMVariantType type;

        Name name;

        FileName filename;

        int row =1;

        int i=0;

        InventTable         inventTableLoc;

        ItemId              itemid;

        TransDate           transdate;

        str                 NewField;

        Dialog dialog;

        DialogField dialogField;

        ;

        application = SysExcelApplication::construct();

        workbooks = application.workbooks();

        dialog = new Dialog("FileOpen");

        dialogfield = dialog.addField(extendedTypeStr(Filenameopen), "File Name");

        dialog.run();

        if (dialog.run())

        {

           filename = (dialogfield.value());

        }

        try

        {

        workbooks.open(filename);

        }

        catch (Exception::Error)

        {

        throw error("File cannot be opened.");

        }

        workbook = workbooks.item(1);

        worksheets = workbook.worksheets();

        worksheet = worksheets.itemFromNum(1);

        cells = worksheet.cells();

        do

        {

            ttsBegin;

        row++;

        itemid    = cells.item(row, 1).value().bStr();

        NewField  = cells.item(row, 2).value().bStr();

        inventTableLoc = InventTable::find(itemid,true);

        inventTableLoc.NameAlias = NewField;

        inventTableLoc.insert();

            ttsCommit;

        i++;

        type = cells.item(row+1, 1).value().variantType();

        }

        while (type != COMVariantType::VT_EMPTY);

        application.quit();

        info("Done");

        info(strFmt("%1", i));

    }

  • Vignesh R Profile Picture
    535 on at

    Hi Dinkar,

    Thanks for your response. Above Code is very helpful to me but the requirement is "import both purchase header and purchase line using one job into Ax Table.

    For Example:

    I have one excel sheet. Excel Sheet contains two sheets. One for Purchase header and another one for Purchase line. I want to import both table in one Excel using one job.

    Regards,

    Vignesh

  • Vignesh R Profile Picture
    535 on at

    Hi Sukrut,

    This link was very helpful to me and thanks for your response. If I have any doubts, i will contact you in future.

    Thanks,

    Vignesh

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans