web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Import Category Hierarchy

(0) ShareShare
ReportReport
Posted on by

Can somebody show me how to import Categories from File?

I've read this and it says I should use the CatImpService. I believe the CatImpService is for Vendor Catalog and the schema of it doesn't match my needed schema. I believe the schema should consists of Name, Code, Description, FriendlyName and other fields seen in Category Hierarchy.

Thank you,

Lyka Tasis

*This post is locked for comments

I have the same question (0)
  • Donna Daem Profile Picture
    5 on at

    Use the following schema. Replace "AAA" with your company name code, replace "####" with the code number for the commodity, and then replace "pppp" with the code number for the parent category for code "####".

    --------------------------START------------------------------

    <?xml version="1.0"?>

    <EcoResCategoryDoc xmlns="schemas.microsoft.com/.../EcoResCategoryDoc">

       <DocPurpose>Original</DocPurpose>

       <SenderId>AAA</SenderId>

       <EcoResCategoryData class="entity">

          <Code>#####1</Code>

          <Name>Commodity A</Name>

          <Parent>pppp</Parent>

       </EcoResCategoryData>

       <EcoResCategoryData class="entity">

           <Code>#####2</Code>

           <Name>Commodity B</Name>

           <Parent>pppp</Parent>

       </EcoResCategoryData>

    </EcoResCategoryDoc>

    ---------------------------END-------------------------------

    Each new category or commodity code has the following schema.

       <EcoResCategoryData class="entity">

           <Code>#</Code>

           <Name>Name</Name>

           <Parent>ParentName</Parent>

       </EcoResCategoryData>

    Please post here if this works for you!

  • venkatesh vadlamani Profile Picture
    3,180 on at

    try using excel addin. This works fine.

    1) before you run this add the category hiearchy record , (first record only) manually in ax first

    After excel addin import

    2) after that you need to run a x++ job calling the method rebuildNestedSubtree() with the hierarchy recid.

    Tips :: All categories should be in chronological order like parent should be a earlier than child

  • Anton Tjiptadi Profile Picture
    2,013 on at

    Hi Venkatesh,

    Can you explain more, how you run the X++ job?

    Thanks,

  • venkatesh vadlamani Profile Picture
    3,180 on at

    static void job1(Args _args)

    {

    EcorescategoryHierarchy hierarchy;

    while select hierarchy

    {

    EcoresCategory::rebuildNestedSubtree(hierarchy.Recid);

    }

    }

    this is to be written in AOT jobs node.

    Normall if you create a category in the hierarchy this method internally readjusts the NestedSetLeft and NestedSetRight  fields which are used by tree control. But through excel addin this is skipped. So above snippet when run will rebuild your nested tree structure  for all the categories related to all the hierarchies in AX

  • Hadji Profile Picture
    5 on at

    Hi venkatesh vadlamani,

    Your suggestion actually worked but there was an error in the Job used to update the nestedtree

    The Actual Method is

    EcoResCategory::rebuildNestedSetTree(hierarchy.Recid) and NOT EcoresCategory::rebuildNestedSubtree(hierarchy.Recid) as posted venkatesh vadlamani.

  • venkatesh vadlamani Profile Picture
    3,180 on at

    Hi Hadji,

    Thank you for correction. Glad that i am helpful

  • Community Member Profile Picture
    on at

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

           }

       }

    }

  • Community Member Profile Picture
    on at

    File format:

    category1,desc1,category2,desc2,category3,desc3,category4,desc4

  • Community Member Profile Picture
    on at

    To import Retail, Basic properties and attributegroups:

    static void ImportHierarchyValues(Args _args)

    {

       RetailAttributesGlobalLookup        globLookup;

       RetailAttributesLegalEntityLookup   entlookup;

       EcoResCategoryAttributeGroup        categoryAttributeGroup;

       EcoResCategoryInstanceValue         ecorescatindval;

       EcoResCategory                      catCurnt;

       Dialog                              dialog = new Dialog("To Import hierarchy values from a file.");

       DialogField                         fileNameToImport = Dialog.addField(extendedTypeStr(FilenameOpen)),

                                           companyNameToImport = Dialog.addfield(extendedTypeStr(CompanyId), "Company Id");

       TextIo                              iOImport;

       RecId                               LegEntityRecId;

       container                           importContainer;

       #File

       ;

       dialog.run();

       if(dialog.closedOk())

       {

           if(!System.IO.File::Exists(fileNameToImport.value()) || !fileNameToImport.value())

           {

               throw error("Invalid file!");

           }

           iOImport = new TextIo(fileNameToImport.value(), #IO_Read);

           iOImport.inFieldDelimiter("|");

           iOImport.inRecordDelimiter("\r\n");

           LegEntityRecId = CompanyInfo::findByCompany_IN(companyNameToImport.value()).RecId;

           importContainer = iOImport.read();

           while(conLen(importContainer))

           {

               ttsBegin;

               catCurnt = EcoResCategory::findByName(conPeek(importContainer,1),EcoResCategoryHierarchy::findByName(conPeek(importContainer,2)).RecId);

               if(catCurnt)

               {

                   if (conPeek(importContainer,3))

                   {

                       categoryAttributeGroup = EcoResCategoryAttributeGroup::findByGroupAndCategory(EcoResAttributeGroup::findByName(conPeek(importContainer,3)).RecId, catCurnt.RecId,true);

                       if (!categoryAttributeGroup)

                       {

                           categoryAttributeGroup.initValue();

                       }

                       categoryAttributeGroup.AttributeGroup = EcoResAttributeGroup::findByName(conPeek(importContainer,3)).RecId;

                       categoryAttributeGroup.Category = catCurnt.RecId;

                       categoryAttributeGroup.Modifier = EcoResCategoryAttributeModifier::Product;

                       categoryAttributeGroup.write();

                   }

                   EcoResCategoryAttributeLookup::synchronizeWithCategoryAttribute(catCurnt);

                   ecorescatindval = EcoResCategoryInstanceValue::findByCategoryInstance(catCurnt.RecId,LegEntityRecId);

                   entlookup = RetailAttributesLegalEntityLookup::findByCategory(catCurnt.RecId,LegEntityRecId,true);

                   if(!entlookup)

                   {

                       entlookup = RetailAttributesLegalEntityLookup::findByInstance(ecorescatindval.RecId, true);

                   }

                   if(!entlookup)

                   {

                       RetailProductAttributesLookup::synchronizeCategory(catCurnt.RecId);

                       entlookup = RetailAttributesLegalEntityLookup::findByCategory(catCurnt.RecId,LegEntityRecId,true);

                   }

                   if(entlookup)

                   {

                       entlookup.BarCodeSetup = conPeek(importContainer,10);

                       entlookup.SiteId = conPeek(importContainer,11);

                       entlookup.WarehouseInvent = conPeek(importContainer,12);

                       entlookup.WarehousePurch = conPeek(importContainer,13);

                       entlookup.WarehouseSales = conPeek(importContainer,14);

                       entlookup.GroupItemGroup = conPeek(importContainer,15);

                       entlookup.GroupInventoryModel = conPeek(importContainer,16);

                       entlookup.UnitInvent = UnitOfMeasure::findBySymbol(conPeek(importContainer,17)).RecId;

                       entlookup.UnitPurchase = UnitOfMeasure::findBySymbol(conPeek(importContainer,18)).RecId;

                       entlookup.UnitSales = UnitOfMeasure::findBySymbol(conPeek(importContainer,19)).RecId;

                       entlookup.update();

                   }

                   globLookup = RetailAttributesGlobalLookup::findByCategory(catCurnt.RecId,true);

                   if(globLookup)

                   {

                       globLookup.BarCodeUseEANStandard  = conPeek(importContainer,7);

                       globLookup.GroupProductDimension  = conPeek(importContainer,4);

                       globLookup.GroupStorageDimension  = conPeek(importContainer,5);

                       globLookup.GroupTrackingDimension = conPeek(importContainer,6);

                       globLookup.cnlSPM                 = conPeek(importContainer,8);

                       globLookup.cnlWFJProductType      = conPeek(importContainer,9);

                       globLookup.update();

                   }

               }

               ttsCommit;

               importContainer = iOImport.read();

           }

       }

    }

  • Suggested answer
    Kumar Gaurav @ MS Profile Picture
    on at

    Hi Lyka,

    Seems your requirement is to map another schema to Catalog schema, in case additional fields are required to be imported then you will have to change the CatImpService to include it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans