Wednesday 28 May 2014

Test Data Transfer Tool Dynamics AX - How it works and what are the possibilities

Earlier I described how to import demo data for AX 2012 R3 using the Test Data Transfer Tool (beta).  

The post will look into it's possibilities and how it works. 

What actually is the Test Data Transfer Tool?
The Test Data Transfer Tool (TDTT) uses SQL Server's Bulk Processing Program (BCP) to move the data from one AX database to another. That means that the business logic validation in AX itself isn't used. On the other hand, it's fast and we like fast. 
In order to be able to use the TDTT, you need to have SQL Server Client Tools installed and run the tool from the server which hosts the database. 

Expressions in the Export
There are four expressions you can use to export: 

.  Match any single character
* Match the previous expression zero or more times. 
(?<! subexpression) Prevent a match if the end of the previously matched content matches the subexpression. This expression is known as a zero-width negative lookbehind assertion.
^ Match the start of the string.

How to export / import
In the command prompt, go to C:\Program Files (x86)\Microsoft Dynamics AX 2012 Test Data Transfer Tool (Beta)\ 

To Export: 
dp export "c:\temp" <databasename> <servername>

To Import: 
dp import "c:\temp\importfilename" <databasename> <servername>

Some possiblities

Export a single or two tables
After installing the tool, you'll have an interesting directory named: [Lists]. Here you can manipulate the tables which are to be excluded from the export (default installation path is: C:\Program Files (x86)\Microsoft Dynamics AX 2012 Test Data Transfer Tool (Beta)\[Lists]).

So, if we would like to exclude all tables, but the table TaxAuthorityAddress, create a new file in the [Lists] folder and the expression should be: 

// Don't export any tables except TaxAuthorityAddress

.*(?<!^TaxAuthorityAddress)

If you only want to export TaxAuthorityAddress and CustTable, the expression would be: 
// Don't export any tables except TaxAuthorityAddress and CustTable

.*(?<!^TaxAuthorityAddress)(?<!^CustTable)


Export a table and filter rows from it
Now we want to export the TaxAuthorityAddress, but only for company NL. In order to do this, you need to create a new file named: filters.xml.

In it, enter the following and save the file in the [Lists] folder. Define the table name and in it, set the field on which you need the filter and the filter value.

<tables>
<table name="TaxAuthorityAddress">
    <filter>
<field>DataAreaID</field> = 'NL'
   </filter>
</table>

</tables>


Import data and run a SQL Script after it
The import tool truncates the table before importing the file. So be aware, you cannot import data only for one company when you have multiple companies in your environment. 

You can create your own SQL scripts and place them in the [import] folder in the TDTT root folder. When the import of the data has been done, the script(s) will be executed. It could be very handy to include a script which updates your parameters to your test environment settings.

As an example, I created a simple script to update my TaxAuthorityId to '007':

USE [DAX2012R3];
UPDATE TaxAuthorityAddress
SET TaxAuthorityId ='007'

WHERE DataAreaId ='NL';

After importing the TaxAuthorityAddress which I exported earlier, you can now see that the field is updated: 




My verdict: nice tool; clean, fast and simple, I like it. 




Monday 26 May 2014

Brand new setup: SQL 2014, Visual Studio 2010, TFS 2013 and Dynamics AX 2012 R3

I've been wanting to upgrade my software setup for some time now and after an inspiring presentation regarding automatic builds (by Kenny Saelen) I decided to fully upgrade my software. In two evenings I installed:

  • SQL Server 2014 developer edition
  • Visual Studio 2010 (AX 2012 isn't compatible with VS2012)
  • TFS 2013
  • Dynamics AX 2012 R3
I had already installed AX, so I only needed to move my databases to the SQL Server 2014 data dir and it was up and running again. 

My laptop is a Dell Intel Core i7, 2.9 GHz, running with 8GB RAM and 128GB SSD. I must say, AX2012 runs pretty smooth and is more than sufficient for my testing purposes. With the help of AXBuild, a complete compile only took 37 minutes. 

A minor issue running into when using Team explorer was that I could no longer create a new Team Project after linking it to TFS 2013. The error was: 
TF30172: You are trying to create a team project either without required permissions or with an older version of Team Explorer. Contact your project administrator to check your permissions or to determine how to upgrade Team Explorer. 

It is required to update your Team explorer for TFS, you can use the following link: http://www.microsoft.com/en-us/download/details.aspx?id=40776.

Now everything is working and as you can see, TFS 2013 is up and running on my local laptop, nice :-).



Tuesday 20 May 2014

Data import export Framework - Copy entity data between companies

The Data import export Framework has the possibility to import or export data from external sources, but you can also copy data from one company to another within AX itself. 

Below you'll find the how to (like importing data, again this is really easy), but first some downsides in my opinion:


  • You can't see the selected companies after having run the wizard. I'd like to now this information to double check. You'd want to see the in the [Copy processing group] form. 
  • Business validations cannot be run when copying the data. I'd want the possibility to check if mandatory metadata is present in my new company and if not, warn me about it, like when importing data. Now you should be careful to validate your data in the staging table and correct errors if there are any. If you forget to do this, you'll enter invalid data in AX and loose your data integrity. 
How to copy the data


To use it, you must select option: [Copy entity data between companies]. It lets you select an entity (in this case Asset):


Next up is the selection of the Source and the Target company, simply select one Source company and one or more Target companies: 


Click next and finish the wizard to set up the copy template. Now all that needs to be done is to Get the Staging data (hit run to fetch the records).


And finally run the job [Copy data to target] to copy the data in the actual AX table. 


The assets are now present in the selected company.




Wednesday 14 May 2014

Create and update production order through code

Here's how to create a production order and update it completely up until ending the order through code for AX2009: 


static void JLH_ProductionOrderViaCode(Args _args)
{
    NumberSeq                       numberSeq;
    ProdTable                       prodTable;
    InventDim                       inventDim;
    ProdMultiCostEstimation         prodMultiCostEstimation;
    ProdMultiScheduling             prodMultiScheduling;
    ProdMultiRelease                prodMultiRelease;
    ProdMultiStartUp                prodMultiStartUp;
    ProdMultiReportFinished         prodMultiReportFinished;
    ProdMultiHistoricalCost         prodMultiHistoricalCost;
    Args                            args   = new Args();
    ;

    ttsbegin;
    NumberSeq                   = NumberSeq::newGetNumFromCode(ProdParameters::numRefProdId().numberSequence);
    ProdTable.ProdId            = NumberSeq.num();
    ProdTable.ItemId            = '5001'; // Item

    prodTable.initFromInventTable(InventTable::find(prodTable.ItemId));
    prodTable.initBOMVersion();
    prodTable.initRouteVersion();
    inventDim.InventSiteId      = 'S1'; // Site
    inventDim.InventLocationId  = 'MW'; // Warehouse
    inventDim = InventDim::findOrCreate(inventDim);
    prodtable.InventDimId       = inventDim.inventDimId;
    prodtable.QtySched          = 2; // Quantity
    prodtable.insert();
    ttscommit;

    // Estimation
    prodMultiCostEstimation = ProdMultiCostEstimation::construct(args);
    runBaseMultiParm::initParm(ProdMultiCostEstimation);
    prodMultiCostEstimation.insert(prodTable, ProdMultiCostEstimation.defaultParmBuffer());
    prodMultiCostEstimation.run();

    // Scheduling
    prodMultiScheduling = ProdMultiScheduling::construct(ProdSchedMethod::OperationScheduling);
    runBaseMultiParm::initParm(prodMultiScheduling);
    prodMultiScheduling.insert(prodTable, prodMultiScheduling.defaultParmBuffer());
    prodMultiScheduling.run();

    // Release
    prodMultiRelease = ProdMultiRelease::construct(args);
    runBaseMultiParm::initParm(ProdMultiRelease);
    prodMultiRelease.insert(prodTable, prodMultiRelease.defaultParmBuffer());
    prodMultiRelease.run();

    // Start up
    prodMultiStartup = ProdMultiStartUp::construct(args);
    runBaseMultiParm::initParm(prodMultiStartup);
    prodMultiStartup.insert(prodTable, prodMultiStartup.defaultParmBuffer());
    prodMultiStartup.run();

    // Report as Finished
    prodMultiReportFinished = ProdMultiReportFinished::construct(args);
    runBaseMultiParm::initParm(ProdMultiReportFinished);
    prodMultiReportFinished.insert(prodTable, ProdMultiReportFinished.defaultParmBuffer());
    prodMultiReportFinished.run();

    // End the Order
    prodMultiHistoricalCost = ProdMultiHistoricalCost::construct(args);
    runBaseMultiParm::initParm(ProdMultiHistoricalCost);
    prodMultiHistoricalCost.insert(prodTable, ProdMultiHistoricalCost.defaultParmBuffer());
    prodMultiHistoricalCost.run();

}

Wednesday 7 May 2014

Data Import Export Framework in AX2012 R3

AX2012 R3 comes with the Data Import Export Framework which is a separate module in AX. It is also part of R2 CU7 and available as a download for 2012 Featurepack (via Information Source). 

I did install it before in the Featurepack version, but it had some minor bugs which held me from futher investigation this possibly cool tool. But after re-discovering this tool, my first impression for the out of the box options are:
Pros: It looks nice, it's comprehensive and let's you preview data which you'd want to import.
Cons: It stills seems a bit shaky, the slightest mistake can result an error which doesn't explain the reason of the failure. Also the drag and drop isn't very smooth (yet?), but it gets the job done.

So how does it work?

In this blog I'll briefly show how you can import data via CSV, but you can also upload via ODBC or via other AX instances. I'll import 4 new main accounts in this example.

First you need to create a Source Data format. In this case I've created CSV of the type File and have set the column delimiter to Semicolon. 



Next, create a new Processing Group (MA with description Main Account in my case) and click Entities, here you can select the type of import (I choose Main Account, but it could also be customers, sales orders, vendors etc.). Select source data format to be CSV and then click Generate Source file to create the input template. Select the fields you want and generate a sample file. 


In the Sample File Path, select your enriched file which you'll import. Then the other options in the top menu become available. 

Select Generate Source Mapping and based on the header line in your import file, the links are created. You can view (and modify) the link from the import file to the table via the button "Modify Source mapping" as can be seen below. When you modify a link (drag and drop), remember to hit the Save button. 


You can preview the file which is to be imported by clicking Preview Source File, it will show the upload to the staging table with the values and fields. 

Close the entities form and return to the Processing Group, hit "Get staging data" to upload the data and click Run. In my case, it results in an infolog which says that 4 records have been inserted in the staging table. Via "Execution History" you can preview the data in the staging table which can now be imported to the table(s) in AX. A last check if all data is correct and then click "Copy data to target" and click Run to import. 

This resulted in 4 new records and my main accounts are created: 


It's really that simple, so go for it and check it out!

Saturday 3 May 2014

Importing Demo Data in DAX 2012 R3

Today I installed AX2012 R3 on my laptop and of course I want the demo data to be imported as well (download via Partnersource). You need to use the Test Data Transfer tool which can be downloaded via InformationSource.

The next step is to extract the demo data and to install the test data transfer tool. After that has been done, open the command prompt in admin mode. Navigate to the folder where the test tool is installed and enter the following command: 

dp [direction] [directory] [database] [server]

direction = Import or Export (import in this case)
directory = the directory which holds the extracted demo data
database = the name of the AX2012 R3 database
server = name of the server (can be left blank when importing on the local machine)



Hit Y to confirm that this is a test environment and you want to import the data. The import will start to process the files.

When the import is complete, you'll have the new companies! The whole import took approximately one hour, great work.