Pages

Tuesday, April 1, 2014

Models: How to enumerate every object and full path in a given Model [AX 2012]

I have some custom Best Practice checks that have required me to crawl over various specific models and paths and I needed a way to enumerate the exact paths of everything in a model, so I wrote some code to do so!

NOTE: This code won't show some objects like Jobs or Shared/Private Projects. It really shows everything you'd want. This is only because the last join to parentModelElement doesn't display records where modelElement.ParentModelElement == 0.

Just comment out the last block to get some of those odd-objects.

        /*
        join Name from parentModelElement
            where parentModelElement.RecId == modelElement.ParentModelElement
        */


static void listAllModelObjects(Args _args)
{
    SysModelElement     modelElement, parentModelElement;
    SysModelElementType modelElementType;
    SysModelElementData modelElementData;
    SysModelManifest    modelManifest;
    
    while select Name from modelElement
        join Name from modelElementType
            where modelElementType.RecId == modelElement.ElementType
        join modelElementData
            where modelElementData.ModelElement == modelElement.RecId
        join modelManifest
            where modelManifest.Name == 'USR Model'
                && modelManifest.Model == modelElementData.ModelId
        join Name from parentModelElement
            where parentModelElement.RecId == modelElement.ParentModelElement
    {
        info(strFmt("%1, %2, %3, %4",
            parentModelElement.Name, modelElementType.Name, modelElement.Name,
            SysTreeNode::modelElement2Path(modelElement)));
    }
                
}

No comments:

Post a Comment