Import Categories from file - AX 2012

I have to import category hierarchies from file in AX 2012. For this we have an AIF option on form. Can anyone please help me by providing sample XML file for import. I tries to import using Excel import but it fails as it cannot set NestedSetLeft and NestedSetLeft. When we import using AIF, does the system take care of filling up these fields or should we provide these values in input xml file.

Can anyone please help me in this?

static void insertCategoryHierarchy(Args _args)
EcoResCategory previousCH, currentCH,rootCH;
EcoResCategoryTranslation transl;
CommaIo fileiovar;
Dialog dialog = new Dialog(“Select file for the input hierarchy”);
DialogField dfield1 = Dialog.addField(extendedTypeStr(FilenameOpen)),
dfield2 = dialog.addField(extendedTypeStr(Name),“Field Delimeter”),
dfield3 = Dialog.addField(extendedTypeStr(cnlEcoResAttributeGroupName)),
dfield4 = Dialog.addField(extendedTypeStr(EcoResCategoryHierarchyId)),
dfield5 = Dialog.addfield(extendedTypeStr(EcoResCategoryName),“Which node to insert”);
container contdata;
int i;
if(!System.IO.File::Exists(dfield1.value()) || !dfield2.value())
throw error(“Invalid file or format”);
rootCH = EcoResCategory::findByName(dfield5.value(),dfield4.value());
if (!rootCH)
throw error(“Node %1 does not exist in %2”,dfield5.value(),dfield4.value());
fileiovar = new CommaIo(dfield1.value(), #io_read);
contdata =;
previousCH = rootCH;

for (i=1; i <= conLen(contdata); i=i+2)
currentCH = EcoResCategory::findByName(conPeek(contdata,i),dfield4.value(),true);
if(currentCH.ParentCategory != previousCH.RecId)
warning(strFmt("%1 not a child of %2. Category ignored. Moving to next record",currentCH.Name,previousCH.Name));
currentCH.Name = conPeek(contdata,i);
transl = EcoResCategoryTranslation::find(currentCH.RecId,“EN-US”,true);
transl.Category = currentCH.RecId;
transl.Description = conPeek(contdata,i+1);
transl.SearchText = conPeek(contdata,i);
transl.FriendlyName = conPeek(contdata,i);
transl.LanguageId = “EN-US”;
previousCH = currentCH;

contdata =;


This code will insert category hierarchy if file in format

node, node description, subnode,subnode description,subsubnode,subsubnode description

node1, node1 description, subnode1,subnode1 description,subsubnode1,subsubnode1 description

But i coudn’t figure out how to insert in retail and basic product properties they have same parent table which does not let me update values.

Hi devilworshiper**,**

Can you please tell me how to use this file with comma separated valu. say for e.g if i wanted to add “bike” as a last node. Then how will i create my file. like

Motor,Motor,Two Wheeler, Two Wheeler, Bike,Bike. Is it will work??