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.

Layer Configuration in AX 2012

Changing Layer in Dynamics AX 2012:


1.      Click Start, point to Administrative Tools, and then click Microsoft Dynamics AX 2012 Configuration. The Microsoft Dynamics AX Configuration Utility opens.





In the Microsoft Dynamics AX Configuration Utility, click Manage, and then click Create configuration. The Create Configuration window opens
In the Configuration name field, enter a name for the configuration, and then click OK. The Create Configuration window closes
On the Developer tab, in the Application object layer to open field, select a new layer from the drop-down list.
On the Developer tab, in the Application object layer to open field, select a new layer from the drop-down list.


In the Development license code field type the license code and  confirm license field also give the same




Click Apply and  Click OK to save the configuration. The Microsoft Dynamics AX Configuration Utility window closes.
Close and restart the client in the new layer.

Share Data to many Companies in Ax 2012

This article describes how Dynamics Ax Virtual Company and Table Collection work. We will also discuss how to move data from normal company to virtual company when you introduce virtual company in existing Ax implementation. 

Virtual Company:
Dynamics Ax stores data as per company in tables. But there might be occasions when you want to share data across companies, like country, state, zip codes data. This sharing of data is achieved by creating a virtual company and storing data in this virtual company. Normal companies are then configured to read/write data from this virtual company. The only purpose of virtual company is to share data across companies, you cannot log into this virtual company.

Before seeing how to do virtual company setup, I would like you to show another trick that can be used to share data across Ax. There is a property on Ax tables called "SaveDataPerCompany", you can use this property to save data globally in Ax. To share data set this property to "No".





Note: This data is shared by all the companies in Ax. This option will delete DataAreaId field and default (DataAreaId, RecId) index from the table. If you want more control on shared data, like which companies can share and which can not then use virtual company. 

Virtual Company setup:



Step 1: Create Table Collection

Decide which tables you want to share and create a table collection for these functionally related tables. For example; if you want to share Global Address Book across companies then you can utilize the existing table collection "DirPartyCollection".


To create a table collection, go to AOT\Data Dictionary\Table Collections and on right click select "New Table Collection", then just drag your required tables in this collection.

Step 2: Create Virtual Company, configure/attach normal companies and table collection


Create a virtual company that will hold the shared data for normal companies.
Note: Before doing the below steps, make sure you are the Ax administrator and the only user online.
  1. Go to Administration -- Setup -- Virtual company accounts, and create a virtual company.

  2. Decide which companies needs to share data and attach those normal companies with this virtual company.

  3. Attach the table collection with this virtual company.



Your Ax client will re-start and you are done with setting up the virtual company account.

Now, when you have virtual company in place, all new data will be saved in this virtual company. Only companies attached to the virtual company can use this shared data. All other companies which are not attached will work normally, these companies will continue to read/write data as per company bases.

How to move existing data to virtual company?
When you setup a new virtual company, Ax does not move data automatically from normal company to virtual company. This is done by system administrator manually.

There are many ways to do this data move, but I will discuss only two approaches here.

Ax Import / Export:


This is standard Ax approach.

  1. Manually export existing normal company data from Ax.
  2. Remove duplicate records from this exported data set. 
  3. Delete exported data from normal companies.
  4. Import the exported data back in Ax, while logged into one of the participating companies. 
  5. Create records deleted in point 2 again in Ax using your logic. How you want to handle duplicate? For example, if you have customer 'Rah' in more than one normal company, what you want to do with this?
Direct SQL:

Use this approach if you have good knowledge about SQL queries and Ax table structures/relationships. Below are few points that will help you understand what to do and how to do.

  • All Ax tables store data as per company unless otherwise specified. For this, Ax uses a special field called DataAreaId. In case of virtual company, it does not matter from which normal company you log-in, it is always the virtual company id which is stored in DataAreaId field of shared tables. 
  • Ax also assigns a unique 64bit number to each record in table. For this, Ax uses a special field called RecId. This RecId is unique in the table and is generated by Ax when you insert a new record in Ax. It is not related to DataAreaId / Company.
  • For unique records between all participating normal companies, update the DataAreaId to the virtual company id.
  • For duplicate records, create them again in Ax using some Ax job or Ax import/export technique.

Attached below are some SQL queries that might help you moving the Global Address Book records from normal companies to the virtual company by changing the DataAreaId.