Friday 27 March 2015

Open a Form using X++ code

how to open a form by using x++ code:

static void OpenDisplayMenuItem()

Args args = new Args();

args.record(VendTable::find("XYZ"));
new MenuFunction(MenuItemDisplayStr(VendTable),MenuItemType::Display).run(Args);
}

------
static void OpenForm()
{ FormRun formRun;
Args args = new Args();
;
args.name(formstr(VendTable));
args.record(CustTable::find("XYZ"));

formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();
}

Saturday 21 March 2015

Inventory Dimensions In Microsoft Dynamics AX 2012

Microsoft Dynamics Ax 2012 gives us the ability to assign a good level of detail to our inventory.
Following are the 9 inventory dimensions that are available in Ax 2012, you can always customize to add more upon your needs :
    1. Size
    2. Color
    3. Configuration
    4. Site
    5. Warehouse
    6. Location
    7. Pallet ID
    8. Serial number
    9. Batch number
To assign these dimensions easily they have been broken down into three dimension groups which can further have the choice of activating/deactivating any particular dimension for that group. The three groups are:
Inventory dimension groups Dynamics Ax
1. Product Dimension group
product dimensions dynamics ax 2012
By default this group contains the following inventory dimensions
    • Size
    • Color
    • Configuration
Style was added to this client to meet their requirements.
2. Storage Dimension group
Inventory storage dimensions dynamics ax 2012
By default this group contains the following inventory dimensions
    • Site
    • Warehouse
    • Location
    • Pallet ID
3.  Tracking Dimension group
Inventory tracking dimensions dynamics ax 2012
By default this group contains
    • Batch number
    • Serial number
Inventory profile, Owner, GTD number were all added for this client after customization. I have purposely shown you screen shots that have more than just the default inventory dimensions so it can be clear that inventory dimensions can be customized to add more dimensions as needed.

How to delete layers in Ax 2012


1. Go to Start-> Administrative tool-> Ax 2012 management shell
2. For example we want to delete user model so type following command:
axutil delete /layer: usr
3. and press enter and put y when prompt for confermation of deletion as shown in secrren shot


Note: Take the back up before exicuting this command and try this first on test server

Friday 20 March 2015

Method Calling Sequences of Table in AX 2012

When you press CTR+N

inItValue()

When you change data in a Field

validateField()  -> validateFieldValue() ->  ModifiedField() ->  ModifiedFieldValue()

When you close the table after entering some data

validateWrite() - > Insert()  -> aosValidateInsert()

When you open the table which will contain some data
If table will contain 10 records this method is called 10 times

aosValidateRead()

When you Save the Record for the first time

validateWrite() ->Insert() - > aosValidateInsert()

When you modify the record and saving

validateWrite() -> update() - > aosValidateUpdate()

When you delete the record

validateDelete() -> delete() -> aosValidateDelete()

Finacial Dimensions in AX 2012

Today we will be exploring the new changes related to Financial dimensions in AX 2012.
Earlier versions AX 2009, 4.0 :

  • In older version System use to limit the creation of dimensions up to 10. 
  • By default 3 dimensions were available in the system namely Department, CostCenter and Purpose.
    Technically these dimensions were controlled by Enum SysDimension and an array EDT Dimension.
  • So If we have 3 enum elements in SysDimension, then its corresponding array elements are stored in    dimension EDT and can be referred as Dimension[0], Dimension[1].....
  • If you would like to store these dimension values against customized table, then simply we were adding the EDT Dimension to that Table. At Form level simply drag and drop field on Group then system use to  show all the array elements as string control.

New version AX 2012 (6.0) : 
  • In AX 60, their is no limit to dimension creations. One can create n number of dimensions as per    organization requirements.
  • Technically their is huge change in framework, the way these dimensions used to be created and stored.
  • Firstly EDT Dimension (array) is deprecated and replaced with DimensionDefault (Int64 RecId).    
  • Financial Dimensions master table Dimension is replaced with DimensionAttribute and DimensionValueDetails.
  • Now if one wish to store these dimension on your customized table then instead of EDT Dimension one should add DimensionDefault EDT.       
  • At Form level make use of DimensionDefaultingController class to show the available dimensions.

How to access Financial Dimensions values in AX 2012: 

     
 In earlier version, accessing dimension values was very simple like
                 CustTable.Dimension[0]      ==  Department  value    
                 CustTable.Dimension[1]      ==  CostCenter  value
                 CustTable.Dimension[2]      ==  Purpose       value

 In AX 60, since they have replaced Dimension EDT with RecId DimensionDefault we have to make use of Dimension helper classes to access values.So in CustTable you will find defaultDimension field which stores reference recId for DimensionAttributeSet.       

 I am referring Customer 1101 in CEU Company, Contoso Demo Data for illustration purpose. Note the dimension values for this customer as shown in below snap.



  
Refer the code to access the values.

static void DEV_Dimension(Args _args)
{
    CustTable                         custTable = CustTable::find("1101");
    DimensionAttributeValueSetStorage dimStorage;
    Counter i;
      
    dimStorage = DimensionAttributeValueSetStorage::find(custTable.DefaultDimension);
  
    for (i=1 ; i<= dimStorage.elements() ; i++)
    {
        info(strFmt("%1 = %2", DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name,        
                               dimStorage.getDisplayValueByIndex(i))); 
    }
}  
  
   
When you run the job, will see as below 


I know that now you might have understood the importance of theses helper classes, they are making our lives easy :) 

Difference Between InMemory and TempDB

  In Memory                                                               Tempdb

1. Holds data temporarily in client or             1. Holds data temporarily in database
      server
2. These tables can't store in the database      2.These tables can store in the database.  
             .
3. Can't apply security.                                  3. Can apply security.   

Import and Export a Model in 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
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:
    • Sign Tool
    • ISV licensing agreement
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 AX60ManagementUtilities.
  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:
  • Install the Microsoft Dynamics AX databases
  • Include cumulative updates and hotfixes in a new installation (slipstreaming)
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 AX60ManagementUtilities.
  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.