Search code examples
exportaxaptax++dynamics-ax-2012aot

How to mimic the AOT Export by layer functionality X++?


I am attempting to programmatically duplicate the following steps in X++

  1. In the AOT Tree right click on the root node and click "Export"
  2. Provide a file name
  3. Click the "Application object layer" checkbox
  4. Specify "cus" as the Application object layer
  5. Export the XPO to the file

I've gotten as far as bring able to export entire AOT tree but I can't figure out a way to narrow it down to just the cus layer. Here is my current code sample ...

TreeNode treeNode;
FileIoPermission perm;

#define.ExportFile(@"c:\XPO\AOTCusExport.xpo")
#define.ExportMode("w")
;

perm = new FileIoPermission(#ExportFile, #ExportMode);
if (perm == null)
{
return;
}

perm.assert();

treeNode = TreeNode::findNode(@"\");
if (treeNode != null)
{
    // BP deviation documented.
    treeNode.treeNodeExport(#ExportFile);
}

CodeAccessPermission::revertAssert();

I have a feeling that the solution lies within the "treeNodeExport" method. There is an "int _flags" property that I am not using. I've looked around but I'm not sure what value to populate the flags with? Has anyone attempted this kind of process duplication before? Am I heading down the right path?


Solution

  • Please have a look on the AOTExport macro.

    Then read this:

    #AOT
    #AOTExport
    TreeNode rootNode = infolog.rootNode();
    ;
    rootNode.treeNodeExport(@'c:\fullaot.xpo', #expKeepIds | #expLables | #expLayer);
    

    I am not sure on how to specify the layers, but it is most likely just a logical OR on the flag argument.

    If in doubt take a look on the SysElementExport form and related classes.

    Update: as expected the layer is specified in the bitmask.

    In \Forms\SysExportDialog\Methods\getutilLayer the mask is specified as:

    return 1 << layer.selection();
    

    So if you want to export the CUS layer you do:

    rootNode.treeNodeExport(@'c:\fullaot.xpo', #export | #expLayer | (1 << (UtilEntryLevel::cus+1)));
    

    There is room for 15 bits for layers as the next flag is:

    #define.expKeepIds(0x0100)