Objects not in Version Control (AX 2012)

If you’ve ever worked in a development environment that utilizes version control I’m sure that you have fell victim to the “missing objects” error during the build phase. This usually happens because sometimes you create objects in the AOT and forget to add them to version control. And at some point you check in other objects that contain references to those missing objects and the build server fails.

In previous versions of AX I developed scripts to scan AOT objects and determine which ones had not been added to version control. These scripts could be very slow executing and usually ended up being used infrequently. Working in AX 2012 I have discovered a quick means of parsing new and modified AOT objects that utilizes the model stores and I applied it to my “Objects not in VCS” script. This new methodology is very quick at determining which items in the system have not been included in the version control system.

By default the following job only scans the current layer and the active model (version control works by layer and model). The model restriction can be omitted to open up scanning of all objects in the layer, but it would defeat the purpose of the script if you were to remove the layer limitation.

static void ObjectsNotInVCS(Args _args)
{
    #SysVersionControl

    SysVersionControlSystem vcsSys = versionControl.parmSysVersionControlSystem();
    SysVersionControllable  controlable;

    UtilEntryLevel  curLayer    = currentAOLayer();
    modelId         curModelId  = xInfo::getCurrentModelId();
    str             modelName = SysModelStore::modelId2Name(curModelId);

    SysModelElementData elemData, parentData;
    SysModelElement     parent, child;
    TreeNode            pNode, cNode;

    //Set options to skip cache lookup of file names
    infolog.globalCache().set(#VCSCache, #NoPrompt,true);

    while select RootModelElement from child
        group by child.RootModelElement, elemData.ModelId
        join ModelId from elemData
            where elemData.ModelElement == child.RecId
                //Layer numbers in SysModel* views are offset by +1
                && elemData.Layer       == (curLayer + 1)
                //Remove the following line to include all models
                && elemData.ModelId     == curModelId
    {
        //Get lowest layer copy of parent
        select firstOnly parent
            order by parentData.Layer
                where parent.RecId == child.RootModelElement
            join parentData
                where parentData.ModelElement == parent.RecId;

        pNode = SysTreeNode::findNodeInLayer(
                      parent.ElementType, parent.name, 0, parentData.Layer - 1); 
        if(!pNode)
            continue;

        controlable = SysTreeNode::newTreeNode(pNode);
        if(!controlable)
            continue;

        if(vcsSys.allowCreate(controlable))
        {
            //do something if it isn't in version control
            info(strfmt("%1 %2",pNode.treeNodePath(), modelName));
        }
    }
}

The RootModelElement of the SysModelElement table contains a direct reference to the base AOT parent object. This allows quicker lookup when parsing multi-level objects such as forms and reports and drastically improves the performance of this script.

It would be a simple task to modify this code to automatically add the missing objects to version control effectively creating an automatic “add missing objects to version control” process.

Enjoy!

Share/Bookmark
This entry was posted in AX 2012, Microsoft Dynamics AX and tagged , , , , , . Bookmark the permalink.