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

What does this mean: "The form datasource query object does not support changing its AllowCrossCompany property after the form has executed the query."?

I have made a form with datasources vendtable and vendtrans. Inside vendtable_ds.executequery() looks like this: QueryBuildDataSource queryBuildDatasource ,queryBDS_VendTrans_Invoice; ; queryBuildDatasource = this.query().dataSourceTable(tablenum(vendtable)); queryBDS_VendTrans_Invoice = this.query().dataSourceTable(tablenum(vendtrans)); if (curext() == "MASTERCOMP") { this.query().allowCrossCompany(true); } else { this.query().allowCrossCompany(false); } //FilterVendorName = stringedit control on form if (FilterVendorName.text()) { queryBuildDatasource.addRange(fieldNum(VendTable,Name)).value(strfmt("*%1*", FilterVendorName.text())); } else { queryBuildDatasource.clearRange(fieldNum(VendTable,Name)); } //FilterInvoiceNumber = stringedit control on form if (FilterInvoiceNumber.valueStr() == "") { queryBDS_VendTrans_Invoice.enabled(false); } else { queryBDS_VendTrans_Invoice.enabled(true); queryBDS_VendTrans_In...

Credit Note [Dynamics AX] using X++

This post will help to create credit note for a sales order based on the invent lot id. All the invoices raised for a particular sales line – Lot Id will be raised back as a credit note. Information on Credit Note: A credit note or credit memorandum (memo) is a commercial document issued by a seller to a buyer. The seller usually issues a Credit Memo for the same or lower amount than the invoice, and then repays the money to the buyer or sets it off against a balance due from other transactions Below Code will help to create credit note for all the invoices raised against the sales line -lot id. Please note: This code can be customized as per your requirements. This is just a template to help creating credit note using X++ code. Please test the code before use. static void SR_CreateCreditNote_Sales(Args _args) { // Coded by Sreenath Reddy CustInvoiceTrans custInvoiceTrans; Dialog dialog = new Dialog(“Create credit note – for sales.”); DialogField dfInv...