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;
#file
;

dialog.run();
if(dialog.closedOk())
{
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);
fileiovar.inFieldDelimiter(dfield2.value());
fileiovar.inRecordDelimiter("\n");
contdata = fileiovar.read();
while(conLen(contdata))
{
ttsBegin;
previousCH = rootCH;

for (i=1; i <= conLen(contdata); i=i+2)
{
currentCH = EcoResCategory::findByName(conPeek(contdata,i),dfield4.value(),true);
if(currentCH)
{
if(currentCH.ParentCategory != previousCH.RecId)
{
warning(strFmt("%1 not a child of %2. Category ignored. Moving to next record",currentCH.Name,previousCH.Name));
break;
}
}
if(!currentCH)
{
currentCH.selectForUpdate(true);
currentCH.initFromParent(previousCH);
currentCH.Name = conPeek(contdata,i);
currentCH.addToHierarchy();
}
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”;
Transl.write();
Transl.clear();
previousCH = currentCH;
}

ttsCommit;
contdata = fileiovar.read();
}
}

}

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??