Skip to main content

Reflection and recursion on the AOT to compare projects.

So I use the base layer compare tool via Tools>Development tools>Version update>Compare layers to create a project of the "CUS" layer (normally the VAR layer for me).  This gets all of the objects modified in the CUS layer in one project.  Then I set that in the #layerCompareProject macro, then add my projects I want to check against in the lower lines of code.

I've used this tool countless times to compare two projects.  Another use I had was during an upgrade to Roll Up 7 from Roll Up 1.  Somehow I had deleted a modification to an obscure table...this made me worried that I could have accidentally deleted other objects that I would have no idea about.  To check this, I went into Live and created a layer compare project of the CUS layer, then went into my upgraded RU7 environment and made the same layer compare project.  Then all I had to do was run the job and it output the objects that were missing.

I think it's clever/fun the way I wrote it too using recursion to reflect on the AOT.  It's basic recursion for traversal.

/*
How to use:
Create a compare project of the layer you want to check and make it SHARED!

MAKE IT SHARED
MAKE IT SHARED
MAKE IT SHARED

Change the constant "layerCompareProject" to the name of the SHARED layer project
you just created

Modify the first line from the main body of the job to be the projects you're searching
customProject = infoLog.projectRootNode().AOTfindChild('Shared').AOTfindChild('Customizations');
traverseAndUpdateMap (customProject.getRunNode().AOTiterator());

Just repeat those two lines to add more projects...it will update and search them
*/
static void ProjReflection(Args _args)
{
    #define.layerCompareProject('CUS_Live')

    ProjectNode layerCompareProject;
    ProjectNode customProject;

    Map map = new Map(Types::String, Types::Integer);
    MapEnumerator enumerator;

    void traverseAndBuildMap(TreeNodeIterator _tni)
    {
        ProjectNode pn = _tni.next();
        ;

        while (pn)
        {
            if (!pn.applObjectType())
            {
                // Recursively traverse the project
                traverseAndBuildMap(pn.AOTiterator());
            }
            else
            {
                // Fill the map with every object we found
                map.insert(pn.treeNodePath(), 0);
            }

            pn = _tni.next();
        }
    }

    void traverseAndUpdateMap(TreeNodeIterator _tni) { ProjectNode pn = _tni.next(); ; while (pn) { if (!pn.applObjectType())
            {
                // Recrusively traverse the project
                traverseAndUpdateMap(pn.AOTiterator());
            }
            else
            {
                if (map.exists(pn.treeNodePath()))
                {
                    // We found an object in a project that already exists in the map
                    // ...mark it as found [1]
                    map.insert(pn.treeNodePath(), 1);
                }
            }

            pn = _tni.next();
        }
    }

    ;

    layerCompareProject = infoLog.projectRootNode().AOTfindChild('Shared').AOTfindChild(#layerCompareProject);
    traverseAndBuildMap(layerCompareProject.getRunNode().AOTiterator());


    // Modify these lines to search projects
    customProject           = infoLog.projectRootNode().AOTfindChild('Shared').AOTfindChild('Customization');
    traverseAndUpdateMap    (customProject.getRunNode().AOTiterator());

    /*
// Add more lines if you want to search more
customProject = infoLog.projectRootNode().AOTfindChild('Shared').AOTfindChild('InstallProj');
traverseAndUpdateMap (customProject.getRunNode().AOTiterator());

customProject = infoLog.projectRootNode().AOTfindChild('Shared').AOTfindChild('BoltOn');
traverseAndUpdateMap (customProject.getRunNode().AOTiterator());
*/

    enumerator = map.getEnumerator();

    info("The following objects from [" + #layerCompareProject + "] were not found in searched projects.");
    while (enumerator.moveNext())
    {
        if (!enumerator.currentValue())
            info(strfmt("%1", enumerator.currentKey()));
    }
}

Popular posts from this blog

Dynamics Axapta: Sales Orders & Business Connector

Well, again folllowing my same idea of writting close to nothing and pasting code, I'll paste in some code to create a sales order from some basic data and the invoice it. I'll try to explain more in the future. AxaptaObject axSalesTable = ax.CreateAxaptaObject("AxSalesTable"); AxaptaRecord rcInventDim = ax.CreateAxaptaRecord("InventDim"); AxaptaRecord rcCustTable = ax.CreateAxaptaRecord("CustTable"); rcCustTable.ExecuteStmt("select * from %1 where %1.AccountNum == '" + MySalesOrderObject.CustAccount + "'"); if (MySalesOrderObject.CurrencyCode.Trim().Length == 0) MySalesOrderObject.CurrencyCode = rcCustTable.get_Field("Currency").ToString().Trim(); string sTaxGroup = rcCustTable.get_Field("taxgroup").ToString().Trim(); //set header level fields axSalesTable.Call("parmSalesName", MySalesOrderObject.SalesName.Trim()); axSalesTable.Call("parmCustAccount", M

Passing values between form and class

Class name is EmplDuplication and Form is EmplTable . void clicked() {    MenuFunction mf;    args args = new Args();    ;     args.record(EmplTable);     mf = new menufunction(identifierstr(EmplDuplication), MenuItemType::Action); mf.run(args); } Meanwhile, in the main() method of the EmplDuplication class, we need to put this Axapta x++ code to get the datasource: static void main(Args args) {     EmplDuplication EmplDuplication; EmplTable localEmplTable; ;     if(args.record().TableId == tablenum(EmplTable)) localEmplTable = args.record();     ... }