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)

Export Data from Ax2012 To Excel CSV Format

(0) ShareShare
ReportReport
Posted on by 2

kindly do let me know if it's possible to export some ax table into Excel file with csv format ? 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    Hi Zohan,

    You can use DMF for this, please refer to this thread discussing similar requirement community.dynamics.com/.../174428

  • Anitha Eswaran Profile Picture
    312 on at

    Hi Zohan,

    I am not clear about your question, Are you asking about the possibility to export the table data to CSV file.

    If this is your query: Yes. it is possible

    Sample is given below

    static void AE_AttributeExport_CSV(Args _args)

    {

       #file

       #define.FileFormat('.csv')

       str                 dateFormat;

       TextIo              textIO;

       FileIoPermission    filepermission;

       Filename                fileName;

       DictTable               dt ;

       DictField              df ;

       FieldId                fieldId;

       int     row = 1 ,FieldCnt, fieldName;

       int     header = 0, i,j;

       System.IO.StreamWriter              streamWriter;

       RetailTmpCatBulkAttrib retailTmpCatBulkAttrib;

       Notes text;

       fileName        = @"f:\anitha\AttributesExport_CSV_Other consoles accessories.csv";

       filepermission  = new FileIoPermission(filename, #io_write);

       filepermission.assert();

       if (WINAPI::fileExists(fileName))

       {

           WINAPI::deleteFile(fileName);

       }

       streamWriter = new System.IO.StreamWriter(fileName);

       dt = new DictTable(tableNum(RetailTmpCatBulkAttrib));

       FieldCnt = dt.fieldCnt();

       fieldId = dt.fieldNext(0);

       header = 0;

       while select retailTmpCatBulkAttrib

              where retailTmpCatBulkAttrib.CatalogName == 'MSPT Catalog' &&

                    retailTmpCatBulkAttrib.AttributeSourceName == "Other consoles accessories"

          {

              text = '';

              if(header == 0)

               {

                   for(i=1;i<=FieldCnt;i++)

                   {

                       fieldId = dt.fieldCnt2Id(i);

                       df = dt.fieldObject(fieldId);

                       if (df.isSql() && !df.isSystem() && df.visible())

                       {

                           text += df.name();

                           text += ";";

                       }

                    }

                   streamWriter.WriteLine(text);

                   header++;

              }

                text = '';

               for(i=0;i<=FieldCnt;i++)

               {

                   fieldId = dt.fieldCnt2Id(i);

                       df = new DictField(tableNum(RetailTmpCatBulkAttrib), fieldId);

                       if (!df.isSystem() &&df.visible())

                       {

                           text += retailTmpCatBulkAttrib.(fieldId);

                           text += ";";

                       }

               }

               streamWriter.WriteLine(text);          

       }

       info("Exported");

    }

  • Grzegorz Skrzypczyk Profile Picture
    225 on at


    Hello,

    thank you for posting this script. There were some minor errors in it. I have included an improved version. It exports a different table but you can change this as required.




    static void S5129937_Export_Data(Args _args) { #file #define.FileFormat('.csv') FileIoPermission filepermission; Filename fileName; DictTable dt ; DictField df ; FieldId fieldId; int row = 0, fieldCnt; int header = 0, i; System.IO.StreamWriter streamWriter; GeneralJournalAccountEntry GeneralJournalAccountEntry; GeneralJournalEntry GeneralJournalEntry; str text; fileName = @"C:\Users\T6416\Desktop\Issues\5129937 Export Data\GeneralJournalAccountEntry.csv"; filepermission = new FileIoPermission(filename, #io_write); filepermission.assert(); if (WINAPI::fileExists(fileName)) { WINAPI::deleteFile(fileName); } streamWriter = new System.IO.StreamWriter(fileName); dt = new DictTable(tableNum(GeneralJournalAccountEntry)); fieldCnt = dt.fieldCnt(); fieldId = dt.fieldNext(0); header = 0; while select GeneralJournalAccountEntry join GeneralJournalEntry where GeneralJournalAccountEntry.GeneralJournalEntry == GeneralJournalEntry.RecId && GeneralJournalEntry.AccountingDate >= 1\1\2016 && GeneralJournalEntry.AccountingDate <= 31\12\2016 && GeneralJournalEntry.SubledgerVoucherDataAreaId == '250' { row++; text = ''; if(header == 0) { for(i = 0; i <= FieldCnt; i++) { fieldId = dt.fieldCnt2Id(i); df = dt.fieldObject(fieldId); if (df.isSql() && df.visible()) { text += df.name(); text += ";"; } } streamWriter.WriteLine(text); header++; } text = ''; for(i = 0; i <= FieldCnt; i++) { fieldId = dt.fieldCnt2Id(i); df = new DictField(tableNum(GeneralJournalAccountEntry), fieldId); if (df.isSql() && df.visible()) { text += GeneralJournalAccountEntry.(fieldId); text += ";"; } } streamWriter.WriteLine(text); } streamWriter.Close(); info(strFmt("Exported %1 rows",row)); }
  • HammadAhmed12 Profile Picture
    30 on at

    It is not exported its giving error

    pastedimage1674110993024v2.png

  • Deepak Agarwal Profile Picture
    8,602 on at

    Have you tried to debug, at what line you are getting this error. There are many examples/blog available for the same job.

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