2

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?

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50

2 Answers2

2

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)
Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
1

You have an example of how to pass flags to the method in the SysTreeNode.toFile() class method

#AOTExport
...
int flags;
...
flags = #expProjectOnly;
...

// This code runs on the client side only
//BP deviation documented
treenodeToExport.treeNodeExport(_filename, #export | #expKeepIds | #expLayer | flags);

...

According to the macro documentation:

// System export flags
#define.noExport(0)                 // Do not export
#define.export(1)                   // Export
#define.expKeepIds(0x0100)          // Export with ID's
#define.expLables(0x0400)           // Export labels
#define.expProjectOnly(0x800)       // Export project only
#define.expLockOnExport(0x1000)     // Lock exported elements
#define.expDefaultValues(0x2000)    // Export default properties values
#define.expLayer(0x4000)            // Export current layer only

you can only export the active layer... what is very strange, as form let you choose a layer from the list. It's a bit more strange when you get inside the SysExportDialog form code, where the list is and the export class is called, and you can't find the layer usage anywhere... so that, may be the macro documentation is right after all.

j.a.estevan
  • 3,057
  • 18
  • 32
  • @estevan Thank you for the reply ! I'm brand new to AX and X++ so forgive my lack of knowledge. Is there a way to set the "current layer" to CUS? I'm thinking that if I can programmatically set the layer then I'll be able to call the Export and get JUST that layer. –  Mar 04 '13 at 13:07
  • 2
    I've investigated a bit this morning and (looking to the X++ code) it's exporting the layer you are connected to. You can connect to any layer as long as you have the password to access that layer. This layer code is delivered by Microsoft along with the license when you buy the application. If you work for the final customer, you need to ask your partner to get this codes, if you work for a partner, you can request it from Microsoft through the "partner source" private site: + info: http://msdn.microsoft.com/EN-US/library/aa611807.aspx http://msdn.microsoft.com/EN-US/library/aa673975.aspx – j.a.estevan Mar 04 '13 at 13:45