Thursday, 2 August 2012

Create a custom entity mapping using the Data Migration Framework [AX 2012]

In my last blog post, I went through the steps to using the Data Migration Framework. This post, I will explain the technical side of it.

To create a custom entity mapping, click on the Data migration framework > Create a custom entity for migration. Follow the wizard and enter your main table you want to import for.

Once the wizard is finished, it will generate an AOT project.


To explain the elements:

Query The query is a definition of the target table. You could add additional table relationships in there if required for mapping.
Table The table suffixed with Entity is the stagging table to use for importing.
EDT The foreign key fields using RecId. The EDT generated is a string field representing the code (identification field).
Class The class is where we can put your business logic. For example, the EDTs with RecId need to be resolved. The below is a screenshot of a method that takes a string code and finds the related RecId (container is just a standard way of returning it).
Then override the getReturnFields, adding your Generate method.

There other more complex uses for the entity class, other than resolving fields. Such as generating whole records like the Global Address book.


Craig said...

Hello Munib.

Thank you for posting about this process.
I am finding no documentation that explicitly addresses how to use the Custom Entity Wizard. I have been able to create a new entity that directly corresponds to one of my own custom tables. But I don't understand how to use an existing entity (for example "customer") and then add my custom fields from CustTable to that entity. Any advice?

Thank you!

Munib Ahmed said...

You actually have to add the fields manually. Refresh the query and add the field to the staging table. Also, if there is any conversion code you need to do for RecId foreign keys.

Would have been nice if the wizard handled it but not with the current version.

Craig said...

Good advice - I appreciate that.

As a follow up (I am testing this now - but would be interested in your perspective!):

If I create a custom entity and assign it the CustTable, will it create a new entity with all my custom fields?

I assume also that the Wizard will create the required methods and the new staging table?


Munib Ahmed said...

Hi Craig,
You wouldn't get any value from running a wizard and creating a new one. The wizard wouldn't create the methods to convert.
It creates a raw staging table and a template class that you can put your code in.
It is just better to just add the fields manually and the methods.

Ambuj Tandon said...

Hi ,
I tried to migrate the demo data that comes bundeled with the dmf installation using the steps given here.
The following error popped up after generating the source mapping and clicking validate.
The source to staging mapping is correct.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Configuration.ConfigurationErrorsException: The value of the property 'address' cannot be parsed. The error is: Invalid URI: The hostname could not be parsed. (C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Microsoft.Dynamics.AX.DMF.ServiceProxy.dll.config line 16)

Please help me.

Munib Ahmed said...

Sounds like you web services aren't running.

Furqan Ahmed said...

i have also faced the same problem as Ambuj and i have started web services but still problem is here

Anonymous said...

Hello !
foremost, I want you to know that my English is very low.

I want to custom entity for data import / export wizzard.

Can you explain to me the methods that you are Inside the class for entity. Example :

thank you.

Prologic Corporation said...

This is a good article & good site.Thank you for sharing this article. It is help us following categorize:
healthcare, e commerce, programming, multi platform,inventory management, cloud-based solutions, it consulting, retail, manufacturing, CRM, technology means, digital supply chain management, Delivering high-quality service for your business applications,
Solutions for all Industries,
Getting your applications talking is the key to better business processes,
Rapid web services solutions for real business problems,
Web-based Corporate Document Management System,
Outsourcing Solution,
Financial and Operations Business Intelligence Solution,

Our address:
2002 Timberloch Place, Suite 200
The Woodlands, TX 77380