Dynamics Search Engine

Friday, February 27, 2009

How to write data into an Excel sheet from Microsoft Dynamics Ax

Note: There is no warranty on this article. Use at your own risk.

This article explains
  • How to write data into an Excel sheet from Microsoft Dynamics Ax using X++ language.
  • How to write data into an Excel sheet using COM object in Microsoft Dynamics Ax.
  • How to export Microsoft Dynamics Ax data into an Excel sheet at run time / dynamically /programmatically using X++ language.
I applied it on Dynamics Ax 2009.

Prerequisite:
  • You should have X++ basic programming knowledge;
Open Ax client > AOT > Jobs node, create a new job and copy the below code segment into your job.

static void writeDataIntoExcelSheetFromAx(Args _args)
{
InventTable inventTable;
Container itemIdCon;
COM comRange;
COM comWorkBook;

COM comWorkBooks;
COM comWorkSheet;
COM comCharacters;
COM comAppl;
str test,test1;
int offset = 65-1; //65 means letter 'A'
str 2 columnId;
str fileName;
str time;
int i;
#define.Excel('Excel.Application')

;

comAppl = new COM(#Excel);
comAppl.visible(true);
comWorkbooks = comAppl.workbooks();
WINAPI::createFile('C:\\test.xls');
comWorkbook = comWorkbooks.open('C:\\test.xls',true,true);
comWorksheet = comWorksheet.new('C:\\test.xls');
comWorksheet = comWorkbook.activeSheet(); //Use
comWorkbook.activateSheet(); in case of Ax 3.0
comWorksheet.select();

while select inventTable
{
columnId = num2char(offset + 1);
i++;
test = columnId + int2str(i);
comRange = comWorksheet.range(test);
comCharacters = comRange.characters();
comCharacters.insert(inventTable.ItemId);

columnId = num2char(offset + 2);
test = columnId + int2str(i);
comRange = comWorksheet.range(test);

comCharacters = comRange.characters();
comCharacters.insert(inventTable.ItemName);
}

WINAPI::createDirectory('C:\\AxData');
time = time2str(timenow(),1,1);
time = strrem(time,':');
fileName = 'C:\\AxData\\' + curuserid() + date2str(today(),123,2,0,3,0,4)+ time + 'test' + '.xls';
comWorkbook.saveAs(fileName);

}

Thursday, February 26, 2009

How to debug x++ code for Microsoft Dynamics AX Enterprise Portal

Note: There is no warranty on this article. Use at your own risk.
I have done this on a single system.


This article explains:

  • How to debug X++ code for Microsoft Dynamics Ax 2009 Enterprise Portal
  • How to debug X++ code using .Net Business Connector
  • How to setup and configure to debug X++ code for Microsoft Dynamics Ax 2009 Enterprise Portal
  • How to debug Microsoft Dynamics Ax 2009 Enterprise Portal (EP)
1.
Log in to the server that is running the AOS.


2.
Open the Microsoft Dynamics AX Server Configuration utility. To open Start > Control Panel > Administrative Tools > Microsoft Dynamics AX 2009 Server Configuration.

3.
Create a new configuration that allows debugging.


3.a.

Click Manage then Create configuration. Give a name to the new configuration in the Create Configuration window then click OK.










3.b.
On the Application Object Server tab, select Enable breakpoints to debug code X++ code running on this server. Click on Apply button.



4.
Click on OK button to close the configuration window. You will get a message that indicates AOS is going to be restarted.

5.
Actually debugger works on the server where IIS is running and Enterprise Portal is hosted. I used a single system and all the things are on the same system. If you are accessing a system remotely using Terminal Services then from the Start menu click Run. Type
mstsc /console in the Open text box and click OK
This opens a console session in Terminal Services. Console session is required to debug Ax EP

6.
The World Wide Web Publish Service should be enabled.
6.a.
Open the Services window for the system. To open it Start > Control Panel > Administrative Tools > Services.
6.b.
Right-click the World Wide Web Publishing Service and click Properties.


6.c.
Click the Log On tab.
6.d.
Select Allow service to interact with desktop as shown below.


6.e.
Click on OK button to close the properties window.

7.
Open the web.config file located in :\Inetpub\wwwroot\wss\VirtualDirectories\\, here the port number of the Enterprise Portal site. If you forgot the port then there is a way to check it out. Open Ax client then Administration main menu > Setup > Internet > Enterprise Portal > Web sites, here you can see the port.



8.
Now do the following:
8.a.
Find out the compilation element then set the debug attribute to true.
8.b.
Save the changes.

9.
Reset IIS by typing the iisreset command at the command-line window or type iisreset in Start > Run > Open text box then click on OK button.

10.
Open the Microsoft Dynamics AX Configuration utility. To open it Start > Control Panel > Administrative Tools > Microsoft Dynamics AX 2009 Configuration.

11.
Set the Application Object Server Instance drop-down menu to Business Connector (non-interactive use only).



12.
Create a new configuration to allow debugging.
12.a.
Click on Manage button then click Create configuration. In the Create Configuration window, name the new configuration then click OK button.
12.b.
On the Developer tab, select Enable user breakpoints to debug code in the Business Connector and Enable global breakpoints to debug code running in the Business Connector or client then click on Apply button.

13.
Click on OK button to close the configuration window.

14.
Open the Microsoft Dynamics AX client.

15.
On the Tools menu, click Options to display the Options window.

16.
On the Development tab, select When Breakpoint from the Debug mode list box, and then click Apply. This enables debugging mode on the client.


17.
Close the Options window.

18.
Open the Microsoft Dynamics AX client.

19.
Now decide the element you want to debug. Lets say you want to debug a class method. Open the method in code editor and write breakpoints where you want to set a breakpoint.

20.
Open the Debugger window manually. To open debugger manually click on Tools > Development Tools > Debugger.

21.
Now execute the web form where the method has been invoked. It should work. On my system it is working perfectly.


If there is any problem please let me know. Definitely I will help you.

Saturday, February 14, 2009

How to use User Controls within .Net to develop or customize Microsoft Dynamics Ax 2009 Enterprise Portal -Part I

Note: There is no warranty on this article. Use at your own risk.

This article explains how to develop or customize Microsoft Dynamics Ax 2009 Enterprise Portal using User Control. How to use Visual Studio (.Net) environment to develop/customize Microsoft Dynamics Ax 2009 Enterprise Portal. How to use Microsoft Dynamics Ax 2009 Data Sets within .Net environment. How to develop or customize Dynamics Ax 2009 Enterprise Portal.

To follow this article you should have installed:
  1. Microsoft Dynamics Ax 2009 with Enterprise Portal
  2. Enterprise Portal should be configured with Microsoft Windows Sharepoint Services 3.0 SP1 or Microsoft Windows Sharepoint Server 2007 SP1. A website for Enterprise Portal should be created
  3. Visual Studio 2008.
You should be familiar with
  • X++ Language
  • Microsoft Dynamics Ax 2009 customization
  • .Net development
  • Microsoft Windows Sharepoint Services product
Now I will explain step by step.

1. Open Microsoft Dynamics Ax 2009 application then AOT. Select Data Sets node, right click on it, and select New Data Set.


2. Rename it to SalesInfo (or any other name whatever you wish) as shown below:


3. Add SalesTable and CustTable to the Data Sources of SalesInfo Data Set as shown below. Make a join between these table.


4. Now open your Visual Studio, click on File->New->Web Site… as shown below



5. From web site template select Dynamics Ax Web Project template, Location should be File System, Language should be Visual C#, and .Net Framework 2.0 as shown below. Click on OK.


6. Now see the Solution window where a project has been created in the name “AxWebProject1”. You can rename it.



7. Right click on AxWebUserControl.ascx page in the solution window then click on View Designer as shown above.

8. Now open the Toolbox and find Dynamics Ax tool section. Drag and drop AxDataSource control from Toolbox to the body of the AxWebUserControl.ascx page.


9. Select the AxDataSource1 on the AxWebUserControl.ascx page then assign a DataSet to it from the AxDataSource Tasks dropdown as shown below. Here you need to select SalesInfo DataSet you created in step1.



10. Go to the Toolbox again and add AxGridView control from Toolbox to the AxWebUserControl.ascx form as shown below.



11.Add AxDataSource1 to AxGridView.


12.Now click on Edit Columns… on AxGridView Tasks.



You will get the below field designer.



13. Add those fields you want to display. I added AccountNum, Name, CustGroup and SalesTable!Status. Later on I modified the fields.



14. Now select the AxWebPartPage.aspx in the solution window. Right click on it. Select View Designer.



15. Now drag the AxWebUserControl.ascx page from solution window and drop it to the body of the AxWebPartPage.aspx. Press F5 to execute the page. See the data is being displayed from Ax in the internet explorer.



Grid format(Template) is also available. See step 12. Auto Format is there.


Now your newly created user control is available in Microsoft Dynamics Ax 2009 AOT. To check go to AOT->Web->Web Files->Web Controls->User Controls.


If it's not available in the AOT then you can add it to AOT.
Right click on .ascx control in the Sulution explorer then click on Add to AOT as shown below



Hope this will be helpful for you.
This is Part I.
In Part II I will let you know how to use this .Net made user control within Dynamics Ax 2009 Enterprise Portal (EP).