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

}

Monday, January 13, 2014

Finding out which tables were updated by an operation in AX 2012

Hello All,

Many a times we simply wants to know what all tables get updated during an operation in Ax. Here is link which shows how to do it in most simplest way.


Microsoft Dynamics AX R3 Training Blitz - Event Invitation

Hello All,

You may like to keep your updated with what is coming up on Dynamics Ax front! Here is link which outlines Microsoft online training/info program for Dynamics Ax 2012 R3.



Please do register for the same.

Dynamics Ax Tips.

Hello All,

Below is link that talks about some nice tips on Dynamics Ax.

http://www.dynamicstips.com/dynamics-ax/getting-started-with-dynamics-ax-2012-getting-crafty-with-formulas/



Thursday, January 2, 2014

How To Iterate all the fields of a table in Ax2012 using x++ code.

In my recent implementation I was having one requirement in this I had to retrieve all the fields of a table and then on certain criteria I had to update these fields in another table. I could do this sing If-else condition but it requires lot of code. So I did it in a better way.

public void updateEstimatesFromCase()
{
    CopyEstimates                   copyEstimates;
    SysDictTable                    dictTable;
    SysDictTable                    caseDictTable;
    SysDictTable                    activityDictTable;
    SysDictField                    dictField;
    SysDictField                    caseDictField;
    SysDictField                    activityDictField;
    FieldId                         fieldId;
    FieldId                         caseFieldId;
    FieldId                         activityFieldId;
    CaseDetailBase                  caseDetailBase = caseDetailBase::find(this.caseId());
    CaseTimeEstimatesTable          caseTimeEstimatesTable;
    ActivityTimeEstimatesTable      activityTimeEstimatesTable;
    ActivityTimeEstimatesTable      buffer;
    ;

    select firstonly caseTimeEstimatesTable
        where caseTimeEstimatesTable.CaseDetailBase == caseDetailBase.RecId;

    select firstOnly activityTimeEstimatesTable
        where activityTimeEstimatesTable.smmActivities == this.smmActivities;

    buf2Buf(buffer,activityTimeEstimatesTable);
    if (activityTimeEstimatesTable.RecId)
    {
        activityTimeEstimatesTable.selectForUpdate(true);
        activityTimeEstimatesTable.update();
    }
    caseDictTable = new SysDictTable(caseTimeEstimatesTable.TableId);
    dictTable = new SysDictTable(this.TableId);
    fieldId = dictTable.fieldNext(0);


    while (fieldId)
    {
        dictField = dictTable.fieldObject(fieldId);
        if (dictField.isSql() && !dictField.isSystem())
        {
            activityTimeEstimatesTable.smmActivities = this.smmActivities;
            if (this.(fieldId) && fieldId != fieldNum(copyEstimates, smmActivities))
            {

                caseFieldId = fieldName2id(tableNum(CaseTimeEstimatesTable),dictField.name());
                activityFieldId = fieldName2id(tableNum(ActivityTimeEstimatesTable),dictField.name());
                activityTimeEstimatesTable.(activityFieldId) = caseTimeEstimatesTable.(caseFieldId);
                if (activityTimeEstimatesTable.RecId)
                {
                    activityTimeEstimatesTable.selectForUpdate(true);
                    activityTimeEstimatesTable.update();
                }
                else
                {
                    activityTimeEstimatesTable.insert();
                }
            }
    }
        fieldId = dictTable.fieldNext(fieldId);
   }
}