Blog

Name is Anant Dubey and the intent to create this blog is to discuss the problems and issues that developer face in the dynamics AX development and to share the new things that come up with the new version of AX.

Wednesday, March 25, 2015

Data Migration Framework (DMF) in ax 2012 R3

Data Migration FrameWork In Ax2012 R3


Index :

  1. Installation and vedio
  2. Copying Data between Companies
  3. Introduction
  4. Creating New Entity 
  5. Enter Data To Customer Table Using DMF.

========================================================================
Please see below links :

http://ax2012dmfdataimport.blogspot.in/

http://technet.microsoft.com/en-us/library/jj225591.aspx
====================================================================
https://www.google.co.in/?gws_rd=cr&ei=OsC3UuD5LIXOlAWivYHoDQ#q=vedios+on+data+migration+framework  _ vedio to learn
=======================================================================
1. Installation : 
https://skydrive.live.com/?cid=b0646cdfdce26c83&id=B0646CDFDCE26C83%21107&Bsrc=Share&Bpub=SDX.SkyDrive&authkey=!AgWRR4apxpbmdyc   -  To install Data Migration Tool

Steps to install  DMF :
http://dynamics-ax.blogspot.in/2012/07/ax-2012-data-migration-framework-step.html  - Steps how to install ( All screens may not come ) .

Extract the folder and you find following components as shown in link .  Run setup as administrator
I got screens

  •  Welcome to DMF (BETA 2)  setup Wizard >> Click Next  
  • Add/Remove Components >> Select ADD
  • Select Components to install ( DataMigrationFrameworkService , Application Object Server  AOS, Client Component) >> I selected all 
  • Next It asks for domain , userid and pass word 
  • Next asks for server name - given Computer name  ( Mycomputer >> Properties ) 
Once after  installation,  we get following components 





I found above in following folders


In my case in C:\Programfiles 3 folders are added 
  • MicrosoftDynamicsAX2012DataMigrationFrameworkClientComponents(Beta)
  • MicrosoftDynamicsAX2012DataMigrationFrameworkServerComponents(Beta)
  • MicrosoftDynamicsAX2012DataMigrationFrameworkService(Beta)  ===================================================================
2.  Copy Data b/w companies in AX
http://technet.microsoft.com/EN-US/library/dn221768.aspx
==================================================================

Introduction

Basically what the framework does is to take data from a data source (for example a CSV file) and copy the data on a staging table before the data is migrated to the final target table. We can make a mapping from source to staging and also a mapping between staging and target. Between staging and target we can also use functions that would be executed to convert the values or even execute some needed logic before the value is copied to target. 


Data Migration Process
1) Prepare Source Data
The file must have a header, which includes the field names identifying each data column.
2) Define type of AX entity to be used
Define entities that will be loaded to AX. For example, Customers, Vendors…
3) Mapping and validation of source file fields to staging AX fields
The DMF tool will allow you to map each field from the source file to an AX field in the staging table. The DMF uses the field names to map the fields in the staging table.
4) Transferring data from source file to the staging table
Once fields from the source file have been mapped to AX fields in the staging table data should be ready to be transferred to the staging table.
5) Transfer of data from staging to target AX destination
Once data has been reviewed and validated in the stating table, the data is then moved to the target AXentity and AX records are created.

Configuration

Data Migration Configuration
1) Determine entities – DMF > Setup > Target entities
There is a set of predefined entities. These entities also include procedures to move data from the staging table to the destination.
2) Define the source data format – DMF > Setup > Source data formats
  • Create a new data format
  • File format: delimited by a character or fixed
  • First row header: indicate if first row of the file, is a header row
  • Row / column delimiter: which character will be used to determine the end of the line / column
  • Text qualifier: indicates characters to encase text and commas
  • Regional settings: regional settings for the file
  • Role separator: used to indicate multiple entries, for example: 317-509 ; 508-999
3) Define the data format for each entity in the source environment 
The data format can be a file that is delimited or fixed width, an ODBC data source, or a Microsoft Dynamics AX table
4/5) Define the processing group / Source to staging table
  • Create a new processing group
  • Entities:
    1. Create a new entity and select the source data format
    2. Run business logic: two flags to enable the check for AX business logic
    3. Sample file path: the path of the file
    4. Generate source mapping: maps the source file against the staging table. If you use AX column names as your header, the DMF tool will automatically try to do the mapping
    5. Modify source mapping: the user can review and modify the mappings
    6. Validate: the validation ensure that all fields in the source file are correctly mapped to the staging table
    7. View target mapping: this option can be used to validate the mappings
    8. Preview source file: the user can view a preview of the source file before the file is copied to the staging table
  • Get staging data: data is ready to be copied to the staging table. This button is used to start the process. A message indicate that the data has been copied to the staging table
6) Moving data from staging table to final ax destination
Select the “Copy data to target”.
Processing Group
======================================================================
http://dynamicsaxspaingermany.blogspot.in/2013/03/dmf-create-custom-entity-for-importing.html

How to Create New Entity using DMF :
http://ax2012dmfdataimport.blogspot.in/

After installing the framework you will be able to start using it with some of the entities that are already delivered like customers, vendors, customer addresses, vendor addresses, open sales orders, ... you can find the entire list in the documentation or in the Target entities form in the Data Migration Framework Area Page.



In our case we want to import ZipCodes and we dont have an entity for that so we will have to create our own entity to create records in the table LogisticsAddressZipCode but also in LogisticsAddressState, LogisticsAddressCounty and LogisticsAddresssCity in case we have to.

To make that we will use the provided Wizard to create the needed AOT Objects. So we use the option Create a custom entity for migration. This will launch the wizard.



We are asked to which table we want to import data. We selectLogisticsAddressZipCode. 



On the next step we are presented the names of the entity table, query and class objects that will be created. We can change it but we leave as proposed.



The result is a project with all the objects created. But we still have some work to do because we want also to create records on the tables LogisticsAddressState, LogisticsAddressCounty and LogisticsAddresssCity. For that we will create methods that will be executed when the system takes the values of State, County and City from Staging table to Target table. These methods will check if the values of State, County or City exists. If not a record would be created on the corresponding table.
public container GenerateLogisticAddressCounty(boolean _stagingToTarget = true)
{
    container res;
    LogisticsAddressCounty logisticsAddressCounty;
    ;
    if(_stagingToTarget)
    {
        select firstOnly logisticsAddressCounty
        where logisticsAddressCounty.CountryRegionId == entity.CountryRegionId
        && logisticsAddressCounty.StateId == entity.State;

        if(!logisticsAddressCounty)
        {
            ttsBegin;
            logisticsAddressCounty.clear();
            logisticsAddressCounty.CountryRegionId = entity.CountryRegionId;
            logisticsAddressCounty.StateId = entity.State;
            logisticsAddressCounty.Name = entity.CountryRegionId;
            logisticsAddressCounty.CountyId  = entity.CountryRegionId;
            ttsCommit;
        }

    }
    res = [logisticsAddressCounty.RecId,logisticsAddressCounty.Name];
    return res;

}
=====================================================================
public container GenerateLogisticAddressCity(boolean _stagingToTarget = true)
{
    container res;
    LogisticsAddresssCity logisticsAddressCity;
    ;
    if(_stagingToTarget)
    {
        select firstOnly logisticsAddressCity
        where logisticsAddressCity.CountryRegionId == entity.CountryRegionId
        && logisticsAddressCity.StateId == entity.State
        && logisticsAddressCity.CountyId == entity.County
        && logisticsAddressCity.Name == entity.City;

        if(!logisticsAddressCity)
        {
            ttsBegin;
            logisticsAddressCity.clear();
            logisticsAddressCity.CountryRegionId = entity.CountryRegionId;
            logisticsAddressCity.StateId = entity.State;
            logisticsAddressCity.CountyId = entity.County;
            logisticsAddressCity.Name = entity.City;
            logisticsAddressCity.Description = entity.City;
            ttsCommit;
        }

    }
    res = [logisticsAddressCity.RecId,logisticsAddressCity.Name,logisticsAddressCity.name];
    return res;

}
===================================================================
public container GenerateLogisticAddressState(boolean _stagingToTarget = true)
{
    container res;
    LogisticsAddressState logisticsAddressState;
    ;
    if(_stagingToTarget)
    {
        select firstOnly logisticsAddressState
        where logisticsAddressState.CountryRegionId == entity.CountryRegionId

        && logisticsAddressState.StateId == entity.State;

        if(!logisticsAddressState)
        {
            ttsBegin;
            logisticsAddressState.clear();
            logisticsAddressState.CountryRegionId = entity.CountryRegionId;
            logisticsAddressState.StateId = entity.State;
            //logisticsAddressState.TimeZone = entity.TimeZone;
            logisticsAddressState.Name = entity.State;
            logisticsAddressState.stateCode_IT = entity.State;
            ttsCommit;
        }

    }
    res = [logisticsAddressState.RecId,logisticsAddressState.Name,logisticsAddressState.name];
    return res;
}
=====================================================================


For each method we will check if the corresponding record exists and if not we will create the record. At the end we will return a container which contains the values that we want to be available for the target table.



We have also to modify the method getReturnFields of our entity class so we indicate for each method which value of the target table will be initialized with the result of the execution of the function.
====================================================================
public static container getReturnFields(Name _entity, MethodName _name)
{
    DataSourceName dataSourceName = queryDataSourceStr(DMFLogisticsAddressZipCodeTargetEntity, LogisticsAddressZipCode);
    Container con = [dataSourceName];
    Name fieldstrToTargetXML(FieldName _fieldName)
    {
        return DMFTargetXML::findEntityTargetField(_entity ,dataSourceName, _fieldName).XMLField;
    }

    switch (_name)
    {
        case methodStr(DMFLogisticsAddressZipCodeEntityClass,GenerateLogisticAddressCity) :
            con += [fieldstrToTargetXML(fieldStr(LogisticsAddressZipCode,CityRecId))];
            break;

        case methodStr(DMFLogisticsAddressZipCodeEntityClass,GenerateLogisticAddressCounty) :
            con += [fieldstrToTargetXML(fieldStr(LogisticsAddressZipCode,County))];
            break;

        case methodStr(DMFLogisticsAddressZipCodeEntityClass,GenerateLogisticAddressState) :
            con += [fieldstrToTargetXML(fieldStr(LogisticsAddressZipCode,State))];
            break;

        default :
        con = conNull();
    }

    return con;

}
========================================================================



We need also to modify the entity table and create a field group per each function we have created with the same name of the function. If not we would be not able to use our functions on the modify entity mapping form later. 



On the Target entities form I can setup now my new target entity. 



And we can modify the fields mapping between staging table and target table clicking on the button Modify target mapping. Below the Mapping details view where we can specify the detail of the mapping.



And below the Mapping visualization. There we can see that our new methods are used between staging and target. Looks cool eh? 



Now we will have only to create a Processing group which uses our new target entity for ZipCodes and map a source file like the one you can see below to the staging table and we would be able to import, first the data to the staging table and later to the target table. 



=====================================================================

http://axmartina.wordpress.com/2013/07/02/dmf-create-custom-entity-mapping-by-using-the-wizard/
http://axmartina.wordpress.com/2013/07/01/data-importexport-framework-in-ax-2012-r2/

========================================================================
5. Entering Customer  Data to AX  :
http://ranaimahmood.blogspot.in/2012/07/ax-2012-data-migration-framework-beta_20.html
You need to select  CustomerEntity_Person.txt - from  following path :
C:\Program Files\Microsoft Dynamics AX 2012 Data Migration Framework Client Components (Beta)\DemoFiles\Delimited\CustomerEntity_Person.txt

Follow the steps and you can get Customer Data in to AX with 4 records.
https://drive.google.com/file/d/0Bz2gDlDZfIivNDVFcmx6RTZNSDg/edit?usp=sharing --- To see the file.
========================================================================
With release of ax 2012 , microsoft has gone to great effort to numeralize data as much as possible.This has resulted  in making the import of data much more difficult. Ex : Customer information is stored more than 9 tables..
It is therefore important to create a tool to facilitate the process of migration of data to the new release of AX. DMF does not come preinstall with installation of AX. when installed it create a module like any other module.

Target entities : Preloaded with installation which are ready to use.
We have a ability to create new entities if necessary - Microsoft provide wizard for it.
DMF tool support several source data formats.  ( like text , deliminator , fixed line, ODBC connection or other AX installation.

Process groups are similar in concept to Definition groups in previous versions.

Here we have the visual representation of Source and Stagging Table. ( Stagging table is intermediate ax table which is the flat representation of customer information.
We can modify by dragging and droping from source to stagging file.

preview source file to preview the data ..

We can also stagging to target mapping ( actual tables in ax side... )

There are some functions that microsoft provided to create the different related tables in ax that are used with  for customer for inserting records. Stagging to target - done by system.

Straight field mappping,


Execution history...

We can also edit the data in Stagging table....

Friday, February 27, 2015

Table Inheritance in ax 2012


1.       Yes, we can now inherit the tables as well which means less code writing and extending the capabilities of base table to be used in derived table.
2.    Two main properties to enable the table inheritance are:
· SupportInheritance
· Extends
3.    Need of Table Inheritance:
· When there is 1:n or n:n relationships between two tables
· When base table and derived table both carry different information about same item/object.
4.       Scenario: The organization has 50 data-cards and allocates it periodically to the employees travelling to customer place. The system need to capture the information of data-cards with their unique number in one table, details of purchase and vendor in second table, data about data-cards issued to employees in third table and data about damage/loss of data-cards in fourth table.
a.        DataCardTable
b.        DataCardPurchaseDetails
c.        DataCardIssueDetails
d.        DataCardDamageLoss.
5.       For table inheritance : The system field InstanceRelationTypeId has been added to the base table and its values refer to derived tables.
6.       Each value in the DataCardTable.RecId column must match a RecId value in one of the tables that derives from DataCardTable.
7.       If we want to enable inheritance we have to set SupportInheritnace to yes on Table, before adding fields to the table. On the base table. Now add InstanceRelationTypeId’ of type Int64. This property tells the system which field must store the table IDs.
8.       Now create a derived table i.e. dataissue details.
9.       In the properties window for derived table, set the “Extends” property to base table i.e. DataCardTable.
10.  

11.   Modification of the record in base table which has corresponding record in derived table would result in same modification of record in the derived table automatically.

Query Classess or Query Object Model in ax 2012

  1. The query object model contains classes to define and run a query. These objects are used to define the query data source.
2.      System class

a.       QueryRun : Executes the query and fetches the data.
b.      Query :The top level of the query definition. This class holds some properties itself and has one or more related data sources.
c.       QueryBuildDataSource :Defines access to a single data source in the query. If more than one data source exists at the same level in a query, they result in separate SQL statements that are executed sequentially. If one data source exists as a child of another data source, a join is created between the two data sources.
d.      QueryBuildFieldList : Defines which fields are returned from the database. The default is that the field list is dynamic, which returns all fields from the data source table, map, or view. Each data source has only one QueryBuildFieldList object, which contains information on all selected fields. It's possible to specify aggregate functions like SUM, COUNT, and AVG on the field list object.
e.       QueryBuildRange : Defines a subset of records returned based on a single field. A range is translated into a WHERE clause in the query SQL statement. If more than one field is used to limit the query (WHERE clause), the data source will contain more than one range.
f.       QueryBuildDynalink : Contains information regarding a relation (limitation) to an external record. When the query is run, this information is converted to additional entries in the WHERE clause of the query SQL statement. Can only exist on the parent data source of a query. The function is used by forms, when two data sources are synchronized. Then the child data source will contain a dynalink or dynalinks to the parent data source. The function is used even if the two data sources are placed in two different forms but are still synchronized.
g.      QueryBuildLink : Specifies the relation between the two data sources in the join. Can only exist on a child data source.


List Page Interaction Class and Methods in ax 2012

Listpage interaction class and methods

Interaction class of list pages extends SysListPageInteractionBase class. Some handful methods of this class are as follows:
. initializing: Called when the form is initializing – Similar to the form init method
. intializeQuery: Also called when the form is initializing – Similar to the datasource init method
. selectionChanged: Called when the active record changes – Similar to the datasource active method.
. setButtonEnabled: Should be overridden to dynamically enable/disable buttons based on the current selection. This is called from the selectionChanged method.
. setButtonVisibility: Should be overridden to show/hide buttons when the form first opens. This is used more to do a one-off layout adjustment based on system configuration/parameters, as well as the menu-item used to open the form. eg If you have a menu-item that opens a form based on status, you may want to hide the relevant ‘status’ field to reduce clutter.
List Pages in AX 2012
Scenario: Add a few fields or buttons to a list page and making it visible/invisible depending on certain conditions. No more possible by writing code on the same form since addition of methods is no more possible in case of LIST PAGES.
We have an interaction class for all the list pages. Taking the example of form -> SalesTableListPage for which the interaction class is -> SalesTableListPageInteraction.

In this class, we have 2 methods:
setButtonVisibility() - To set the buttons visible/invisible
setGridFieldVisibility() - To set the fields visible/invisible


To make a button visible/invisible, we can write below code:
this.listPage().actionPaneControlVisible(formControlStr(SalesTableListPage, NewGroup),false);

To make a field visible/invisible, we can write below code:this.listPage().listPageFieldVisible(formControlStr, (SalesTableListPage,SalesTable_lftCostHoldReasonCode),false);

AX2012 List Pages - Performance Improvementss

I’ve been working on some performance issues recently, and some of these were related to list page performance in AX 2012. The problem is that for some of the list pages, even with CU3, the main query performance is slow due to the fact that the query parameter OPTION(FAST) is not being added automatically to the SQL statement, as it does with most standard forms in Dynamics AX. For some customers this does not create a performance problem, but others may experience slowness opening the list-pages due to their data constellation. I’ve identified some of the list pages where this could be a problem, see the workaround notes below:
Vendor List Page
Object: Query > VendTableListPage > Data Sources > VendTable
clip_image001
Change the “FirstFast” property on the “VendTable” in this view to “Yes”.
clip_image002
Sales Table List Page
Object: Query > SalesTableListPage > Data Sources > SalesTable
clip_image003
Change the “FirstFast” property on the “SalesTable” in this view to “Yes”.
clip_image004
Released Product List Page
Object: Query > EcoResProductPerCompanyListPage > Data Sources > InventTable
clip_image005
Change the “FirstFast” property on the “InventTable” in this view to “Yes”.
clip_image006
Main Accounts List Page
Object: Query > MainAccountsListPage > Data Sources > MainAccount
clip_image007
Change the “FirstFast” property on the “MainAccount” in this view to “Yes”.
clip_image008
CustTable List Page
Object: Query > MainAccountsListPage > Data Sources > CustTable
clip_image009
Change the “FirstFast” property on the “CustTable” in this view to “Yes”.
clip_image010
Ledger Trial Balance List Page
Object: Query > LedgerTrialBalanceListPage > Data Sources > DimAttrvalueCombo
clip_image011
Change the “FirstFast” property on the “DimAttrvalueCombo” in this view to “Yes”.
clip_image012

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXmQeI7wa7muqLO4FkzDeqSxfa3YaP2JVP0o9AuTVFtYKayjoVEeCZDMq81HYcpd6a5DFUQg6-3bRi3plzNq8O0yRE2HCA8Nph4yY1LelqLGrrTo6-ehN2aEWRI6m0vdOAIm_aorXP69M/s1600/Dynamics_AX_2012_Multiselect_scenarios.png
public void init()
{
    FormRun                 callerForm;
    FormDataSource          formDataSource;

    MultiSelectionHelper    multiSelectionHelper;
    MultiSelectionContext   multiSelectionContext;

    ProjTable       projTable;

    super();

    if (!element.args().caller())
    {
        throw error("@SYS22539");
    }

// ************** The standard way of doing it in Dynamics AX 4 and Dynamics AX 2009 **************
    callerForm = element.args().caller();
    formDataSource = callerForm.dataSource();

    ListView.add("Approach 1");

    for(projTable = formDataSource.getFirst(1); projTable; projTable = formDataSource.getNext())
    {       
        ListView.add(strFmt("%1 - %2",projTable.ProjId, projTable.Name));
    }

// ************** Using the new MultiSelectionHelper class in Dynamics AX 2012 **************
    multiSelectionHelper = MultiSelectionHelper::createFromCaller(element.args().caller());

    projTable = multiSelectionHelper.getFirst();
    ListView.add("Approach 2");

    while (projTable)
    {       
        ListView.add(strFmt("%1 - %2",projTable.ProjId, projTable.Name));
        projTable = multiSelectionHelper.getNext();
    }

// ************** Using the new MultiSelectionContext class in Dynamics AX 2012 **************
    multiSelectionContext = element.args().multiSelectionContext();

    projTable = multiSelectionContext.getFirst();
    ListView.add("Approach 3");

    while (projTable)
    {       
        ListView.add(strFmt("%1 - %2",projTable.ProjId, projTable.Name));
        projTable = multiSelectionContext.getNext();
    }

    if (!ListView.getCount())
    {
        throw error("No projects selected");
    }
}



Ax client forms can easily be published to enterprise portal by the new feature from the Menu item >> Deploy to EP.
Let me help with an example:
Create a new List Page by using the template option provided in AX 2012 as shown below and name it as SR_EcoProductListPage as shown below
List page
Change the Name of the newly created list page to SR_EcoProductListPage as shown below.
ECOListPage
Now, let us use the query property on the data sources property to get the linked data sources from the query
Right click on the Data sources Node >> properties >> set the query property to ecoResProductListPage as shown below
DS Query
Next, Go to Design Node >> and give the caption, title data source as shown below.
Design
Next, On the grid set the data source as EcoResProduct as shown below.
grid

Drag and drop some fields on to grid from the Data sources >> EcoResProduct. I have dragged and droppedDisplayProductNumber and ProductType fields on to grid as shown below.