Share via


How to programmatically create a project for objects in a given layer

This article introduces a code example to describe how to programmatically create a project for objects in a given layer in Microsoft Dynamics AX.

Applies to:   Microsoft Dynamics AX
Original KB number:   2004467

Summary

You may want to create a Microsoft Dynamics AX project that contains all of the application elements that exist in a given layer. For example, if you need to recreate the VAR layer *.aod file, you will need to pull all of the application elements in the VAR layer into a project, export the project to an xpo, delete the VAR *.aod file and finally log into the newly created VAR *.aod file import the xpo. When you import the xpo all of the application elements can be recreated in the new *.aod file. The code in this document demonstrates how to do this.

More information

When the X++ code in this example is added to a job in the AOT and executed, the code will create a private project called VarLayerChanges. The VarLayerChanges project will contain all of the elements that exist in the VAR layer. If you would like to create a project for a different layer, change the string 'VarLayerChanges' to the layer you need it for, for example 'CusLayerChanges'. Then, change the enum UtilEntryLevel::var to the different layer, for example UtilEntryLevel::cus.

TreeNode treeNode = infolog.projectRootNode();
ProjectNode projectNode;
UtilElements utilElements;
;
treeNode = treeNode.AOTfirstChild();
treeNode.AOTadd('VarLayerChanges');
projectNode = treeNode.AOTfindChild('VarLayerChanges');
projectNode = projectNode.getRunNode();
while select utilElements WHERE utilElements.utilLevel == UtilEntryLevel::var
{
    ProjectNode.addUtilNode(utilElements.recordType, utilElements.name);
}
ProjectNode.AOTsave();