Friday, May 18, 2012

AxUtil GUI

If you find that the AXUtil tool for importing models is not so pratical, here's the tool for you.

I've extended the functionality of the standard "Installed models" form inside Tools -> Models Management to let you Import, Export, Move or Delete models directly from AX. How it works: With a little of reverse engineering i found that AxUtil.exe simply uses a DLL named AXUtil.dll. This DLL is already referenced in AX, so you can use it directly from X++.

Here's a sample to export a model. The code is pretty straightforward, I just pass in the name of the DB, the path where to export the file and some other params, and then I get my model saved/imported/moved/deleted.

Here you can find the project for the tool, this will work on every client (you don't need to be on the AOS to export/import models)

 private void exportModel(SysModelManifest _SysModelManifest, filePath path)  
   Microsoft.Dynamics.AX.Framework.Tools.ModelManagement.AxUtil        axutil      = new Microsoft.Dynamics.AX.Framework.Tools.ModelManagement.AxUtil();  
   Microsoft.Dynamics.AX.Framework.Tools.ModelManagement.AxUtilContext     context     = new Microsoft.Dynamics.AX.Framework.Tools.ModelManagement.AxUtilContext();  
   Microsoft.Dynamics.AX.Framework.Tools.ModelManagement.AxUtilConfiguration  config     = new Microsoft.Dynamics.AX.Framework.Tools.ModelManagement.AxUtilConfiguration();  
   Microsoft.Dynamics.AX.Framework.Tools.ModelManagement.ModelArgument     modelArgument;  
   int     modelId = _SysModelManifest.Model;  
   int     i;  
   Object ret;  
   ClrObject o; // = new ClrObject("System.Collections.Generic.List`1[System.String]");  
   ClrObject enumerator;  
   boolean hasErrors;  
     modelArgument = new Microsoft.Dynamics.AX.Framework.Tools.ModelManagement.ModelArgument(modelId);  
     config.set_ExportFile(path + _SysModelManifest.Name);  
     axutil.Export(context, config);  
     o = context.get_Errors();  
     enumerator = o.GetEnumerator();  
     while (enumerator.MoveNext())  
     o = context.get_Warnings();  
     enumerator = o.GetEnumerator();  
     while (enumerator.MoveNext())  
     hasErrors = context.get_HasError();  
       info(strFmt("Esportato modello %1 nel file %2" , _SysModelManifest.Name, path + _SysModelManifest.Name));  
   catch ( Exception::CLRError )  
     throw Exception::Error;  


Munib Ahmed said...

Not sure if there are issues with not turning off the AOS. I usually turn off the AOS before exporting.
This is because of an issue I experienced in the past.

But someone suggested using the Flush for the label issue.

Unknown said...

+1 Laudacher

Unknown said...

Hi! Great tool! I began write job with the same requirements, but found your project. Thank's a lot!

Some addition.

inside class method M_DEVModelUtils.exportModel() line 21
config.set_Database(SysSQLSystemInfo::construct().getloginDatabase()); have to change to