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, 25 March 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....