Dynamics Search Engine

Showing posts with label Ax MS Excel. Show all posts
Showing posts with label Ax MS Excel. Show all posts

Tuesday, February 21, 2012

In Microsoft Dynamics AX 2012 during data import using Excel Add-Ins you may experience an exception or error

In Microsoft Dynamics AX 2012 during data import using Excel Add-Ins you may experience an exception like: “You must include at least two items in any list used for updating data.”

Applied on:
Microsoft Dynamics AX 2012 CU2.

Assumption:
This article is for those who has at least basic data flow and navigation
knowledge.

About this article:
This article may answers your question like-
• In Microsoft Dynamics AX 2012 how to handle exception during data import or data conversion?
• In Microsoft Dynamics AX 2012 how to copy master data from one environment to another environment and handle exception or error?
• In Microsoft Dynamics AX 2012 what are the new feature to export / import data?

Exception:

Resolution:
During data import using Excel Add-ins tool you need to select table(s). Once the table(s) is selected, by default system will select field(s) from table which is mandatory or part of primary index. If you have more than two fields like this then you will not face this exception or error. If there is one field which is mandatory or part of primary index in your table then system will select that field and put in the excel sheet and manually you need to select one more field along with this. In the above error screen if you see the red marked area where one more field to be added to get out of this exception.
Hope this is useful.

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);

}