Saturday, September 20, 2014

How to: Export and Import a Model [AX 2012]

How to: Export and Import a Model [AX 2012]


Applies To: Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012
A model is a set of elements in a given layer. Each layer consists of one or more models. Models can be exported to files that have the .axmodel extension. These files are called model files. Model files are deployment artifacts that can be imported into a model store.
A model is permanently associated with the layer that is created in. If you need to move one of your models from one layer to another, you must create a project from the model in the AOT, export the project as an xpo file, create a target model in the desired layer, delete the original model to avoid having to resolve layer conflicts, and import the xpo file to the target model. If you are moving elements between models in the same layer, you can use the Move to model command in the AOT.
You can use either Windows PowerShell cmdlets or the AXUtil command-line utility to export models to model files and import model files into a model store.
ImportantImportant
In Microsoft Dynamics AX 2012, element IDs and element handles are assigned during installation. Therefore, you must avoid randomizing element IDs and element handles when you install models. In general, never delete a model and then reinstall it. Always install a model over an existing model. For more information, see Maintaining Installation-Specific Element IDs and Element Handles.
Preparing the system
Drain client connections and validate permissions
  1. Drain the client connections to the Application Object Server (AOS) instance that you are working with. For more information, see Drain users from an AOS.
  2. Validate that you have appropriate permissions to work with the model store:
    • Administrative permissions on the local computer
    • System Administrator rights in Microsoft Dynamics AX
    • In Microsoft SQL Server:
      • Membership in the Securityadmin server role on the SQL Server instance
      • Membership in the db_owner role in the Microsoft Dynamics AX database

Exporting model files

You can export a model file if you want to distribute it internally or to customers. If you plan to distribute a model file to customers, we recommend that you strong-name sign the model. To strong-name sign a model, you must use the Strong Name Tool, SN.exe, to generate a key pair file.
Export an .axmodel file (Windows PowerShell)
  1. On the Start menu, point to All Programs, point to Administrative Tools, and then click Microsoft Dynamics AX Management Shell.
  2. At the Windows PowerShell command prompt, PS C:\>, type the following command, and then press ENTER.

    Export-AXModel –Model <name> -File <Filename.axmodel> 
    


    This example exports the specified model to a file that has the specified file name.

    You can use the –Server, –Config, or –Database parameters to specify the environment to export from.
    You can also use the -Key parameter to specify the strong-name key pair file to use to sign a model.
    For more information, see Export-AXModel.

  3. You can also use the Sign Tool to sign the file with a digital certificate, or the AXUtil genlicense command to Authenticode sign a file. For more information, see:
 
Export an .axmodel file (AXUtil)



  1. On the Start menu, click Command prompt.

  2. Navigate to the directory for the management utilities. Typically, the location of this directory is %ProgramFiles%\Microsoft Dynamics AX\60\ManagementUtilities.

  3. At the command prompt, type the following command, and then press ENTER.
    axutil export /model:<modelname> /file:<filename> /verbose

    This example exports the specified model to a file that has the specified file name.
    You can use the [/key:SNK-file] parameter to specify the strong-name key pair file to use to sign a model.

  4. You can also use the Sign Tool to sign the file with a digital certificate, or the AXUtil genlicense command to Authenticode sign a file.

 
Importing an .axmodel file

When you import a model, elements in the model that you are importing may conflict with another model in the same layer. In this situation, you can create a conflict model in the patch layer that is associated with the layer that you are working in. You can then resolve the conflicts in the conflict model.
By default, when you import a model from Windows PowerShell or AXUtil, the installation mode is set to display the Model code upgrade checklist when the Microsoft Dynamics AX client starts. If you import a model by using Setup.exe, by default, the installation mode does not display the Model code upgrade checklist. For more information about importing a model by using Setup.exe, see:

By default, optimization steps, such as reindexing the model store, are performed when a model is installed for the first time. Optimization steps are also performed if the number of elements in a model increases by more than 50 percent when the model is reimported. For more information, see How to: Optimize a Model Store for Runtime.
Import an .axmodel file (Windows PowerShell)



  1. On the Start menu, point to All Programs, point to Administrative Tools, and then click Microsoft Dynamics AX Management Shell.

  2. At the Windows PowerShell command prompt, PS C:\>, type the following command, and then press ENTER.

    Install-AXModel -File <Filename.axmodel> -Details

    This command installs the specified file in the same layer that it was exported from.
    You can use the –Server, –Config, or –Database parameters to specify the environment to import to.
    By default, you will be prompted to install the model based on whether it has been signed. The following table describes the prompts shown.

















    ScenarioPrompt
    The model file is not signed.The model is not signed. Are you sure you want to install this model (Y/N)?
    The publisher is recognized from the digital certificate.The model is signed by ‘{0}’”. Would you like to continue (Y/N)?
    The publisher was not available from the digital certificate.The certificate for the model was not recognized. Are you sure you want to install this model (Y/N)?
    The provider for the certificate is unknown.The certificate for the model was not recognized. Are you sure you want to install this model (Y/N)?

     
    If the installation fails because of a conflict, we recommend that you rerun the cmdlet, and use the -Conflict Push option to push the element that has the conflict to the related update layer. You can then resolve the conflict. For more information, see How to: Resolve Conflicts After Importing a Model.
    For more information, see Install-AXModel.

Import an .axmodel file (AXUtil)



  1. On the Start menu, click Command prompt.

  2. Navigate to the directory for the management utilities. Typically, the location of this directory is %ProgramFiles%\Microsoft Dynamics AX\60\ManagementUtilities.

  3. At the command prompt, type the following command, and then press ENTER.
    axutil import /file:<filename> /verbose

    This command installs the specified file in the same layer that it was exported from.
    If the installation fails because of a conflict, we recommend that you rerun the command, and use the /conflict:push option to push the element that has the conflict to the related update layer. You can then resolve the conflict. 

Wednesday, September 17, 2014

X++ Code to Export AOT Object / automatic backup of xpo's.

X++ Code to Export AOT Object / automatic backup of xpo's.

we need to take daily backup of our development (interms of xpo) , but we all always forget becuase of our hectic work schedules.
So use the following job and build batch application to take backup of developement in terms of xpo .
We can take aod also but the size will be more and needs to stop AOS everytime .

Following job illustrates how to export/backup all AOT Classes object.

void GJ_ExportTreeNodeExample()
{

TreeNode treeNode;
FileIoPermission perm;

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

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

perm.assert();

treeNode = TreeNode::findNode(@"\Classes");
if (treeNode != null)
{

// BP deviation documented.
treeNode.treeNodeExport(#ExportFile);
}

CodeAccessPermission::revertAssert();
}

Enjoy !!!!!!!!

“Connection with the Application Object Server could not be established”

“Connection with the Application Object Server could not be established”

Scenario:
Installing Dynamics AX 2009/2012 in two different domains or two different networks. AOS serverin one domain (192.168.1.xxx network) and users and AX Client PC/ terminal servers in other domain (10.5.1.xxx network).
  1. When a AX client from a laptop attempts to connect to AOS you receive the following message or error “Connection with the Application Object Server could not be established”.
Solution:
It is network problem and you can solve it.
Open host file (c:\windows\system32\drivers\etc\hosts) on the AX Client PC or Terminal Server. Add IP address of AOS server and AOS server name
192.168.1.25     AOSServer
in host file then Run the command nbtstat-R and start Dynamics AX Client.

Sunday, September 14, 2014

SysOperation framework part 1:


SysOperation framework part 1:


In Dynamics 2012, the runbase and RunbaseBatch has been replaced sysoperation framework. The main difference between the old and new framework is as following,
Runbase and RunbaseBatchSysoperation framework
No controller class.Controller class to perform operation such as which UI to show.
No contract class. Use of marcoContract class to store the data which need to display on the UI
No UI classSeparate UI class to handle the event and operation related to UI
No Service classService class to perform the business operation base on the input.
In sysoperation framework we have three main classes which are as following
  1. Controller Class:
    1. The purpose of controller class is to perform the following operation
      1. Determine which UI should be used.
      2. Determine whether the operation can be perform in Batch.
      3. Determine the caption of the dialog
  2. Contract Class:
    1. The Contract class is use to save user input and gives it to service class to perform the service. It has parm methods for each of the field which will be shown on dialog.
  3. Service class:
    1. The service class is use to perform the business operation which is required. It must have a method which have attribute of EntryPoint. This method will be called by sysoperation framework when the user click on the Ok button on the dialog. Additionally, the method must take the contract object as the argument of this class.
  4. UI class (optional)
    1. The UI class is used to create the UI of the dialog. This is operation class and should only be added if you have some validate need to perform on the modification of dialog control.
After creating these classes you need to create a menuitem to launch this dialog. The menuitem should be created for controller class and it also has service class information in it. Which is given in parameter field of menuitem.