March 14, 2013

Exporting data to Excel from axapta x++

Exporting data to Excel from axapta x++





Hi All!
Sometimes we need to export data from Microsoft Dynamics AX to Excel using axapta x++ code and we don't know how to do this...
Exists some differents ways to do this, but I think the best way is using the SysExcel class of Dynamics AX and its related.
The only problem I found using this class... is that it can not be used in a batch process.
Sample code:


static void TheaxaptaCreateExcel(Args _args)
{
   SysExcelApplication  xlsApplication;
   SysExcelWorkBooks    xlsWorkBookCollection;
   SysExcelWorkBook     xlsWorkBook;
   SysExcelWorkSheets   xlsWorkSheetCollection;
   SysExcelWorkSheet    xlsWorkSheet;
   SysExcelRange        xlsRange;
   CustTable            custTable;
   int                  row = 1;
   str                  fileName;
   ;
   //Filename
   fileName = "C:\\Test.xlsx";
   //Initialize Excel instance
   xlsApplication           = SysExcelApplication::construct();
   //Open Excel document
   //xlsApplication.visible(true);
   //Create Excel WorkBook and WorkSheet
   xlsWorkBookCollection    = xlsApplication.workbooks();
   xlsWorkBook              = xlsWorkBookCollection.add();
   xlsWorkSheetCollection   = xlsWorkBook.worksheets();
   xlsWorkSheet             = xlsWorkSheetCollection.itemFromNum(1);
   //Excel columns captions
   xlsWorkSheet.cells().item(row,1).value("Account Num");
   xlsWorkSheet.cells().item(row,2).value("Name");
   row++;
   //Fill Excel with CustTable AccountNum and Name fields (only 20 records)
   while select custTable
   {
      if(row == 20)
        break;
      xlsWorkSheet.cells().item(row,1).value(custTable.AccountNum);
      xlsWorkSheet.cells().item(row,2).value(custTable.Name);
      row++;
   }
   //Check whether the document already exists
   if(WinApi::fileExists(fileName))
      WinApi::deleteFile(fileName);
   //Save Excel document
   xlsWorkbook.saveAs(fileName);
   //Open Excel document
   xlsApplication.visible(true);
   //Close Excel
   //xlsApplication.quit();
   //xlsApplication.finalize();
}

-Harry

March 12, 2013

How to Connect the Host Hard Drive to a VirtualBox OS

How to Connect the Host Hard Drive to a VirtualBox Guest OS

VirtualBox from Oracle is an amazing and free application if you like testing different operating systems without messing up your original operating system or Master Boot Record (MBR). VirtualBox is also useful if you like to test operating systems before their final release. 
However, most people want to connect their host hard disk drives to the guest operating system. For your information, the host OS is the operating system you’re actually using, while the Guest OS refers to the OS virtually installed inside VirtualBox. 

We’ve used Windows 7 as the host operating system and Windows XP as the guest OS. Let’s begin.

Step 1 : Install Guest Additions

1start How to Connect the Host Hard Drive to a VirtualBox Guest OS

First off, you need to start up the operating system you want to connect your hard disk drives to. Choose your OS and click the start button. When the OS is ready, click Devices  

> Install Guest Additions.

2installguest How to Connect the Host Hard Drive to a VirtualBox Guest OS.

Clicking this will prompt the Guest Addition setup menu on Windows XP (Guest OS). Install the guest addition and reboot your guest OS as required.

3guestadditionsetup How to Connect the Host Hard Drive to a VirtualBox Guest OS

Step 2 : Share Folder

When installed and rebooted, click Devices again and choose Shared Folders.

4 How to Connect the Host Hard Drive to a VirtualBox Guest OS

A box will open. Simply click the add icon (+ sign) on the right. From the Folder Path pull down menu, click Other.

5addshare How to Connect the Host Hard Drive to a VirtualBox Guest OS

A folder browser (similar to Windows Explorer) will open up. From here, you can select any hard drive or any folder inside a hard drive. Upon selecting click OK.

6select How to Connect the Host Hard Drive to a VirtualBox Guest OS

Step 3 : Connect to Shared Folder

Now, VirtualBox has shared the selected hard drive/folder (in our case, E drive) with the guest OS. You now need to access it. To do so, go to My Computer and in Other Places, right click on My Network Places and choose Map Network Drive.

7map network drive How to Connect the Host Hard Drive to a VirtualBox Guest OS

Here in the Drive box, you have to select a Drive letter for the folder/hard disk drive you’re connecting to. You can choose randomly or select as your choice from the pull down menu. From the Folder box, click the browse button and click the plus sign on the left of ‘VirtualBox Shared Folders’ and then ‘\\vboxsvr’.
This will show you a list of folders or hard drives shared with the guest OS. Click the one you want to connect to and click OK. On the Map Network Drive, make sure the Reconnect at logon checkbox is checked if you want to automatically connect to this drive each time your guest OS starts up.

8add How to Connect the Host Hard Drive to a VirtualBox Guest OS

Step 4 : Access Shared Folder

You’re done! Now, go to My Computer and you’ll be able to access the hard disk drive of your computer right from the guest operating system installed inside VirtualBox.
9network drives How to Connect the Host Hard Drive to a VirtualBox Guest OS

I hope it was easy for you to follow this tutorial and now you are able to access your hard disk and install any software from your local hard disk drive.

-Harry