Monday, 13 October 2014

Create/Delete Customer using AIF Service Class in Dynamics AX

The Application Integration Framework allows us to create/update/delete or read data. Now in AX2009 we have a facility of creating/deleting records using AIF Service classes. There is "NO ADDITIONAL AIF SETUP"(Like Enabling Endpoints etc.) required to execute the code via service class. The services can be used to read/write data in AX.
X++ service class job is illustrated below. 

tatic void Services_CustTable_Create(Args _args)
    // Customer Service class
    CustCustomerService     custService;
    CustCustomer                customer;

    // Data object of Service class
    CustCustomer_CustTable  custTable;
    AifEntityKeyList               entityKeyList;
    AccountNum                    accountNum;

    //Service instance
    custService =  CustCustomerService::construct();

    customer = new CustCustomer();
    custTable = customer.parmCustTable().addNew();


    // Create Customer
    entityKeyList = custService.create(customer);

        accountNum = entityKeyList.getEntityKey(1).parmKeyDataMap().lookup(fieldnum(CustTable, AccountNum));

static void Services_CustTable_Delete(Args _args)
    AifEntityKeyList          entityKeyList;
    AifEntityKey               aifEntityKey;
    // Data object of Service class
    CustCustomerService     custService;
    CustTable                     custTable;

    aifEntityKey  = new AifEntityKey();
    entityKeyList = new AifEntityKeyList();
    custService   = CustCustomerService::construct();

    select firstonly custTable
        where custTable.Name == "Cust_Service";


        // Delete Customer
        info ("CustTable record was successfully deleted.");

SO Creation:

static void Services_SO_Create(Args _args)
    // Sales Order Service class
    SalesSalesOrderService     salesService;
    SalesSalesOrder                salesOrder;

    // Data object of Service class
    SalesSalesOrder_SalesTable  salesTable;
    SalesSalesOrder_SalesLine    salesLine;
    AifEntityKeyList                   entityKeyList;

    SalesId                                salesId;

    //Service instance
    salesService =  SalesSalesOrderService::construct();

    salesOrder = new SalesSalesOrder();
    salesTable = salesOrder.parmSalesTable().addNew();
    salesLine   = salesTable.createSalesLine().addNew();

    // Mandatory data filled for SalesTable

    // Mandatory data filled

    // Create Sales Order
    entityKeyList = salesService.create(salesOrder);
        salesId = entityKeyList.getEntityKey(1).parmKeyDataMap().lookup(fieldnum(SalesTable, SalesId));

Wednesday, 8 October 2014

Working with models in AX 2012

How to: Export and Import a Model AX 2012

 Run:  enter: Cmd >> go to specified path C:\Program Files\Microsoft Dynamics AX\60\Server\MicrosoftDynamicsAX\bin

Type the following command:
// creating the Model in the Layer
AxUtil.exe  create /model:"Name" /Layer:CUS

// exporting the model to file
AxUtil.exe export /model:"NAME" /file:"Name".axmodel

// importing the model from file
AxUtil.exe import /file:Name.axmodel 
>>  /config:instanceName ( import to correct AOS)
>> /createparents (in case of conflicting with system model)

// delete the model
AxUtil.exe delete /model:"Name"
or  AxUtil.exe delete /model:<model working id>

//delete the layer
AxUtil.exe delete /layer:ISV

// if you have multiple instances running
//delete the layer from the database and AXserver.
AxUtil.exe delete /layer:ISV /db:<database> /s:<server>

// full compile from AX2012 CU7 AxBuild:
axbuild xppcompileall /s=01

Axbuild xppcompileall /aos=01 /log="E:\log" /altbin="C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin" /compiler="C:\Program Files\Microsoft Dynamics AX\60\Server\AX2012R2\bin\ax32serv.exe"

AxBuild.exe can accomplish a full compile of all X++ code, into AX p-code, many times faster than the traditional compile that you start from the MorphX client menu.

How to deploy Dynamics AX2012 reports:
  1. Through AOT
    AOT > SSRS Reports > Reports > right click on report > Deploy Element
  2. Through Visual Studio
    Open the report project > Right click on the project or solution node > Deploy
  3. Through PowerShell
    Publish-AXReport -ReportName *

Step by step: import layer without losing data

Step 1. Create a model and move all the objects that you want to move out of the layer.
Tool > Model Management > Create model

Step 2. Create a project of this model and export the project as an xpo.
Tool > Model Management > Create project from model

Step 3. Backup the database and delete the old model created in step 1

Step 4. Synchronize the database from the AOT. This will delete the data but we will retrieve it later.

Step 5. Import the xpo from step 2

Step 6. Synchronize the database.

Step 7. Export this new model.

Step 8. Restore the database that was backed up from step 3

Step 9. Import the new model (step 7), Synchronize and compile
This restores the I’d values of the objects and tables / fields. So no data will be lost

Step 10. Delete old model, compile / synchronize.

How to: Open Visual Studio with a Specific Configuration or Layer [AX 2012]

To Open Visual Studio with a Specific Configuration from a Shortcut

1.       On the client computer that is running Visual Studio, open the Start menu, right-click Visual Studio 2010, and select Properties.
2.       Update the Target field and add the /AxConfig switch with either the name of the client configuration or the name of the client configuration file as shown in the following examples:

"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" /AxConfig z:\Config\ContosoDev.axc

If you run the Visual Studio executable with a parameter of /?, then it will show you all the available switches you can use.

We now have a new node in AOT – Label Files

All labels in the system are grouped under this node.
Now suppose we have a label from another installation which we want to bring in to our system. Right click on the Label Files node and select Create from File. Browse and selct your .ald file. Once you select the file and hit OK, a new node is added under the Label Files node corresponding to the label file imported. You will get an info message saying “Imported label file:C:\Users\Administrator\Desktop\MyLabelen-us.ald”

In AX 2009, after placing a label file, we needed to restart the AOS so that the label index was build. This isn’t required in Dynamics AX 2012. Just try using the label somewhere, and you will see that it is immediately referenced.
If you search in your application folder, you wont find the label file there. The application folder is located here C:\Program Files\Microsoft Dynamics AX\60\Server\MicrosoftDynamicsAX\bin\Application\Appl\Standard
In Dynamics AX 2012, the label file is imported in your current model.
Now let us restart the AOS and see what happens. After restarting the AOS, go back to your application folder and try to find the label file again. This time the label file will be found.
Point to remember, on every AOS restart, all label files will be copied to the application folder from the model store. So your label files are contained in your models but they are stored in your application folder as well.
Now let us try to delete the label file. Right click on your label file. Do you see a delete/remove option?
The answer is no. So how do we delete the label file then? The solution which I figured out was,
To create a temporary model
Move our label file to the temporary model
Stop the AOS
Delete the temporary model
Start the AOS
Let us get about with these tasks
Go to Tools -> Model management -> Create model
Enter name as TemporaryModel. Press OK. You will recieve an info message saying “The model TemporaryModel was created successfully in layer var.”
Right click on your label file and select “Move to model”
Select the TemporaryModel checkbox and press OK.
Stop the AOS.
Open a command prompt. We will be using the command line utility AXUTIL to delete the model.
Issue the following command in the command promptAXUTIL delete /model:TemporaryModel
You will be prompted if you want to delete the model or not. Press Y
Start the AOS
Delete the label file from your application folder as well.

When you open AX now, you will get a dialog saying that “Your model store has been modified.” This is normal because each time you perform an operation on a model, you will get this dialog. Depending on your operation, you should select one of the option. Since we just deleted a model which just had a label file, select Skip.
Open AOT and notice that the label file is deleted now.

Monday, 21 July 2014

“Connection with the Application Object Server could not be established”

Installing Dynamics AX 2009/2012 in two different domains or two different networks. AOS server in one domain ( network) and users and AX Client PC/ terminal servers in other domain ( network).
  1. When a AX client from a laptop attempts to connect to AOS you receive the following message or error “Connection with the Application Object Server could not be established”.
It is network problem and you can solve it.
Open host file (c:\windows\system32\drivers\etc\hosts) on the AX Client PC or Terminal Server. Add IP address of AOS server and AOS server name     AOSServer
in host file then Run the command nbtstat-R and start Dynamics AX Client.

Tuesday, 8 July 2014

Import Contoso Data Using Test Data Transfer Tool(Beta)

1-      Download the test data transfer tool from the below mentioned link.

2-      Download demo data for AX2012 R3 from partner source site.


  • Extract the demo data files from DynamicsAX2012R3DemoData.exe to a specific location.
  • The output folder will contain the files of following extension types:
  1. .OUT—– data file that contains metadata for AX transactional database
  2. .OutModel —- data file that contain metadata for AX model database
  3. .XML —- data file that contains AX table data.
  •  Run the Test Data Transfer Tool.Exe file to install the utility.


  • After successful installation, the folder will look like as shown below:
  • Open AX client and import the .XPO named (MetaDataXMLGenerator.Xpo)


  • On successful import a job will be created as shown below:
  • Run the job <MetadataXMLGenerator(usr)>, a  meta data file will be generated and the path will be displayed in the infolog as shown in the snapshot below:

  • Copy the metadata file from the above path and paste it in [lists] folder (where Test Data Transfer Tool has been extracted). If the file already exists, then overwrite the file.
  • Stop MS Dynamics AX service.
  • Open command prompt using administrator and navigate to the path where the Test Data Transfer Tool is extracted).
  • Run the following command:
Dp.exe Import “C:\R3DemoData\DynamicsAXR3DemoData” DynamicsAXR3
C:\R3DemoData\DynamicsAXR3DemoData—— update the path accordingly
DynamicsAXR3—— provide the actual database name.

If you are multiple instances of a database server then use below,
Dp.exe Import “C:\R3DemoData\DynamicsAXR3DemoData” DynamicsAXR3 “DatabaseServerName\InstanceName

If we enter ‘Y’, then following screen will open up describing the count for importing the table data and Error (if they come up)


  • The process may prolong depending upon machine configuration.
  • On successful import, Open AX client and data will show up.

Microsoft Dynamics AX 2012 Troubleshooting Help Server problems

Some time ago we get several problems with Help Server. Simply when we wanted to access help from Microsoft Dynamics Ax 2012 client we get following problems:
1. Error:
Unable to contact server http://ServerName:Port/DynamicsAXHelpServer/HelpService.svc
To troubleshoot this problem you need to check on client if you are able to access the help server service from Internet Explorer. The url for Help Server service you can find in System administrator > Setup > System > Help system parameters. When in IE you get error like:
Could not load type 'System.ServiceModel.Activation.HttpModule'
then you need to apply following KB article:
2. The other problem we can see is that we get page with “No results” and we cannot see the content of help. For this issue there can be several causes:
a. Double check in Internet Explorer if you can retrieve help files by accessing ie. http://ServerName:Port/DynamicsAX6HelpServer/Content/Microsoft/EN-US/UserHelp/6a9bdc61-b19e-4cea-8890-805a4ccba8b2.htm?DocumentSet=UserDocumentation&ContentLanguage=en-us&ResourceLanguage=en-us
b. Double check if Windows Search Service is up and running
c. Check if content directory is indexed and indexing is finished (Control Panel > Indexing options)


d. In indexing options for File Type htm and html are “Index Properties and File Contents (You need to click Advanced button)


c. If you go to Advanced properties of directory Content the property “Archive and Index attributes” is set up to “Allow files is this folder to have contents indexed in addition to file properties”
d. This is very strange but if help server content is installed in directory of SharePoint ie: C:\inetpub\wwwroot\wss\VirtualDirectories\8082\DynamicsAX6HelpServer\Content the Search Service does not return correct files and the Help Server does not work correctly. So far we have no idea why does it happen but the workaround is to uninstall Help Server and install it on Web Application which physical path points to ie:  C:\inetpub\wwwroot\8082\DynamicsAX6HelpServer\Content

Wednesday, 28 May 2014

AX 2012 R2 to AX 2012 R3 Upgrade

AX 2012 R2 to AX 2012 R3 Upgrade
The latest upgrade guide is very well written and covers the complete upgrade process.  However, I am listing down an overview of the upgrade process and things to remember before starting the upgrade. I hope, this shall enable you to achieve a smooth upgrade.

Things to remember before starting the R2 to R3 Upgrade 

  1. Before installing AX 2012 R3, All R2 components needs to be uninstalled in the environment in which the upgrade is planned.
  2. During the code & data upgrade process, Make sure that you Mark all the steps in the code/data upgrade checklist before you restart AX client/AOS as complete even though it is not yet completed else a blank(empty) start up application workspace will be displayed and no modules will be listed when you re-open the AX client.  
  3. Always compile the application using command “axbuild xppcompileall” from the command prompt whenever compilation is required during Code/data upgrade process.
  4. Please make sure that the below steps are followed else during the data upgrade, the pre-sync and post-sync jobs might struck in ‘Ready’ status and may not be executed.

a.     The user account logging into the Dynamics AX client to run the checklist is the Dynamics AX admin account and NOT just a member of the system administrator security role.
b.     Check the userinfo table in SQL: select * from userinfo where ID = 'admin'  to make sure a record for the "admin" ID has  a valid SID, networkdomain, and networkalias for each partition in the environment. 
c.     Check the batch form directly in the client by going to System Administration | Batch Jobs | Batch Jobs and check the Createdby fields and if the DataUpdate job has already scheduled as an account other than admin, you need to start the upgrade over by logging in as the admin account or you may be able to change the records in the batch and batchjob tables to be the admin account. 
d.     Remove any records in the SysServerSessions table that are not valid in this environment, you should do this while the AOS servers are stopped and make sure to have a SQL backup first.
e.     Check the setup under system administration | setup | system | Server configuration
f.      Delete any AOS instances here that are not valid in this environment.
g.     Make sure the remaining AOS instance is marked “is batch server”
h.     Make sure batch server schedule is setup with proper start/end time i.e. Start time 12:00:00 am end time 11:59:59, so there are no gaps in the scheduled time.
i.      Make sure that the remaining valid AOS server that is also marked for batch has the blank batch group and data Update batch group assigned to it.
j.      Change the status of any other batch jobs from waiting to withhold so they don't interfere with the Data Upgrade batch jobs.  To change the status highlight the jobs you want to change and select Functions | Change Status and choose Withhold
k.     Check for any previously running batch jobs that are stuck in a status of Executing.  You may need to change the status to cancelled or remove the Job from the Batch and Batchjob table from the SQL backup.

Upgrade Steps

Step 1. Synchronize, Compile and Generate CIL on the AX 2012 R2 application.
Step 2. Stop AOS & then back up model and business data databases.

Step 3. Restore the model and business data databases in a new environment.

Step 4. Start the AX 2012 R3 installation setup on a new environment.

Step 5. Select only the databases component.

Step 6. Select configure existing databases.

Step 7. In this step, Assign the R2 database and make sure that the Baseline database name field is left blank during this procedure.

Step 8. On the Select additional models page, select the Foundation model, Foundation Upgrade model, and any other models that you require for your deployment. Select the Foundation Labels model only if you are using country/region-specific features.
After this step, the system creates a new baseline database which contains upgraded AX 2012 R3 models in the SYS, GLS, FPK, and SLN layers and Non-upgraded customer models in the ISV, VAR, CUS, and USR layers.

Step 9. Now install all other required AX components.

Step 10. Now, assign the database and upgraded baseline database in this step.

Step 11. Once, the installation is completed then compile the whole application using the command “axbuild xppcompileall” from the command prompt. This compiled the whole application for me in just 30 to 40 minutes.

Step 12. Now restart AOS and proceed with the code upgrade & data upgrade checklists. Follow the code upgrade document on the complete details.