Wednesday, January 15, 2014

Compare objects among 2 or more layers in Ax2012


Sometime we might like to find objects existing in two or more  layers i.e. layer 1 AND layer 2. Out of box we have a feature of creating a project for objects present in specific layers i.e. layer 1 OR layer 2.
So with below job you can build on this standard feature thereby finding common objects i.e. objects present in all(AND condition) the specified layers only.


Note : If you try to iterate whole AOT thru code it becomes performance intensive hence not advisable to do it. So always create one project and then further work on it. 

static void listAllObjectosFromProject(Args _args)
{

  ProjName                         projName = "CompilerOutput"; // Specify your project area name here

  ProjectListNode                  list = infolog.projectRootNode().AOTfindChild("Shared");

  TreeNodeIterator                 ir = list.AOTiterator();
  ProjectNode                      pnProj,projectNode;
  ProjectNode                      pn = list.AOTfindChild(projName);
  SetEnumerator                    setEnumerator;
  Set                              set;
  container                       layers;
  #define.ProjectName("Compileroutput_Sub") // Sub project Name. You may like to change it as per you like.


   void searchAllObj(projectNode rootNode)
    {
    #TreeNodeSysNodeType

    TreeNode          childNode;
    TreeNodeIterator  rootNodeIterator;
    ;

    projectNode = SysTreeNode::getPrivateProject().AOTfindChild(#ProjectName);
    if(!projectNode)
    {
        projectNode = SysTreeNode::createProject(#ProjectName,ProjectSharedPrivate::ProjPrivate);
    }

    if (rootNode)
    {
      rootNodeIterator = rootNode.AOTiterator();
      childNode = rootNodeIterator.next();
      while (childnode)
      {

        if (childNode.treeNodeType().id() == #NT_PROJECT_GROUP)
         searchAllObj(childNode);

        else
          {
            //info(strfmt("Group :%1 - Object: %2", rootNode.AOTname(), childNode.AOTname()));
            set = childNode.AOTLayers(false);

            setEnumerator = set.getEnumerator();
            layers = conNull();

            while(setEnumerator.moveNext())
            {
               layers = layers +enum2Symbol(enumName2Id('UtilEntryLevel'),setEnumerator.current());

            }

            if(confind(layers,'syp') && confind(layers,'usr')) // Put your layers here in which you want to check objects
            {


                info(strFmt('Name: %1, Layers: %2', childNode.AOTname(),con2Str(layers) ));

                projectNode.addNode(childNode);
                projectNode.AOTsave();

            }


        }
          childNode = rootNodeIterator.next();
    }
  }
}





  if (pn)
  {
    info(strFmt("Project %1:", projName));
    pnProj = pn.loadForInspection();
    searchAllObj(pnProj);
    pnproj.treeNodeRelease();
  }
  else
    info("Projet objects");

}

No comments:

Post a Comment