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.