Import From Excel Using X++ Code For BOMVersion And Bom Table

Company/Product information management/Common/Released products → Engineer Tab->BOM->Line

Now Show a Form

How to Import Data from excel That Form Using X++ Code(JOB) in AX 2012

Here is the code . Change it according to your need (Table and data )…

static void EXCLImport_ClassGroup(Args _args)


SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;

int row;
Name name,itemid;
FileName filename;
ClassGroup ClassGroup; // Table name
int countrec,skipRec;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
//specify the file path that you want to read
filename = “C:\Upload\INVENTORY\Master upload\25032017\CLASSGROUP.XLSX”;

catch (Exception::Error)
throw error(“File cannot be opened.”);
// row++;
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
itemId = cells.item(row, 1).value().bStr();
name = cells.item(row, 2).value().bStr();
ClassGroup.ClassGroupId = itemId;
ClassGroup.ClassGroupDetail = name;
countrec = countrec + 1;

type = cells.item(row+1, 1).value().variantType();
while (type != COMVariantType::VT_EMPTY);
info(strFmt(“Total Records Inserted %1”,countrec));



Why are you again insisting on writing code? Shouldn’t your goal be to do such things without coding? You really should leverage the Data Import Export Framework as much as possible; writing custom code should be the last resort. And using a job rarely makes a good sense, unless you have just a few lines of code and you don’t care about performance.

Hi Martin…,
I am Newly Join This Platform So My senior Assign The Task Using Code …,

Can u explain this clearly…Have u tried the above code…

Hi Martin,

i agree with you but some time we also got this kind of requirement where seniors want to upload data through a job or query instead of DMF . As per them DMF is lengthy process for such small data and some time it also not function fully.

If you will see above code there are only 2 fields which we uploaded and using hardcode path as it was one time upload for us for a new functionality.

First, you need to learn how to import data from Excel through code, then you can apply it to any kind of data. (there are lot examples over web on importing data from Excel)
The next thing would be what data you are trying to import, it could be anything BOM versions, items, purchase order, sales order etc. For that purpose you need to understand the application, you can try by creating that data manually and understand the data flow.It may take time, but this will help you to understand the application and data flow better.

First of all, while your code fills only two fields, it’s only because it doesn’t solve the problem - here we’re talking about BOMTable and BOMVersion tables, which obviously have more fields and business logic. But even in your case, writing something like 30 lines of code is still more work than not writing any code at all. And you’ll have to test and maintain it.

DIXF already comes with BOM and BOMVersion entities, which also encapsulate necessary business logic, which you would have to write again. You can simply use them without any coding and you’ll get support from Microsoft if there is a problem.

If “seniors” don’t know how to use DIXF (and why putting business logic to jobs is bad), it’s probably a good time to educate them.

1 Like