torsdag den 17. juni 2010

Finding differences in code layers between installation

When working with customizations in Dynamics AX I consider it best practice to have several installations for the same customer.

At a minimum you should have a development environment, a development test environment, a test environment besides the production environment that the customer runs in daily business.

DEV.
The development environment is for hacking away, developing and doing research and experiments.

DEV TEST.
The development test environment is for testing the customizations (inhouse QA) before releasing it to the customer for test.
The transfer of customizations between DEV and DEV TEST is done by exporting and
importing .xpo-files.


TEST.
The TEST environment is where the customer makes acceptance test of customizations.
The transfer of code to the TEST enviroment is preferably done by copying layer (.aod)-files from the DEV TEST to the TEST, allowing for release/build control.
If successive deliveries must be done, this can be again be done by exporting importing code AS LONG AS YOU ENSURE EXPORTING AND IMPORTING IS DONE WITH ID'S AND LABELS using an outer layer.

By doing the above described, you avoid having ID-conflicts, when doing RELEASE-upgrades.
A release/buld can the be delivered by copying the .aod and label-files from the DEV TEST to the TEST, and deleting outer layers where successive test-deliveries have been made. Thus when you deliver a release/build you have all customizations rolled up in the layer you use for release.

PRODUCTION.
When making a delivery to the production environment, this is preferably done by delivering layer-files. Again succesive deliveries for hotfixes can be done, by observing the above mentioned rules for the TEST environment (exporting / importing with ID'S and LABELS).


When working as a consultant you are sometimes challenged by having to take over a customer from someone else.
It can become even more challenging, if your predecessors have not been taking the above best pratice rules in to consideration, and you have doubts if the environments TEST and PRODUCTION are in synchronization.
Of course if recently deliveries have been made for test by the customer they wouldn't be.

But some times hotfixes are made directly in the production, and not carried back to the DEV and DEV TEST environments thus leaving the risk that the hotfix will be overwritten by a new release from the DEV TEST to TEST and further on from TEST to PRODUCTION.

I recently had this situation happen to me, and needed to get an overview of the differences between the layers in TEST and PRODUCTION.
Best practice was not followed in this case, so no DEV and DEV TEST enviroments were present, and hotfixes had been made directly in the production.

So I took the layers from the production environment and copied them to the appl / old folder under the TEST enviroment, and used a litte job to build a list of the differences.

Using this list, I was able to pull the code from the PRODUCTION missing in the TEST environment to the TEST environment, so that a release from the test environment weas made.

Se code below:


static void UtilElementsFindDiffInLayers(Args _args)
{
UtilElements newElement;
UtilElements uppElement;
UtilElementsOld oldElements;
UtilElements delElement;
UtilElementType type;
UtilEntryLevel level = UtilEntryLevel::cus;
Container types = [UtilElementType::TableInstanceMethod, UtilElementType::TableStaticMethod, UtilElementType::ClassInstanceMethod, UtilElementType::ClassStaticMethod];
UtilElementId uid = 0; //ClassNum(SysTableBrowser); // init UID if running on specific element
if running on specific element
boolean testMode = false; // TRUE to only test
Counter i;

type = conpeek(types,i);
while select newElement
order by utilLevel
where newElement.utilLevel > UtilEntryLevel::dip &&
(newElement.parentId == uid || !uid)
join oldElements
where oldElements.utilLevel == newElement.utilLevel
&& oldElements.name == newElement.name
&& oldElements.recordType == newElement.recordType
&& oldElements.parentId == newElement.parentId
{
if (oldElements.source != newElement.source)
{
info(strfmt("Layer: %1 Difference: %2 %3.%4",enum2str(newElement.utilLevel),global::enum2Value(oldElements.recordType),xUtilElements::parentName(newElement),oldElements.name));
}
}
}


ATTENTION: As always - USE CODE AT OWN RISK.