Thursday, January 18, 2018

How to create DSN and connect to an External Database from X++

Go to Administrative Tools  >>  Data Sources (ODBC)

In the tab User DSN >> Add >> Choose SQL Server Native Client

Config DSN to your database and server




Sample Database

X++ Code

static void DSNConnectivityTest(Args _args)
{
    LoginProperty                   loginProperty;
    OdbcConnection                  odbcConnection;
    Statement                       statement;
    ResultSet                       resultSet;
    str                             sql, criteria;
    SqlStatementExecutePermission   perm;

    // Set the information on the ODBC.
    loginProperty = new LoginProperty();
    loginProperty.setDSN("TestDatabase");

    loginProperty.setDatabase("TestDB");

    odbcConnection = new OdbcConnection(loginProperty);

    if (odbcConnection)
    {
        sql = "SELECT * FROM Persons;";

        perm = new SqlStatementExecutePermission(sql);
        perm.assert();

        //Prepare the sql statement.
        statement = odbcConnection.createStatement();
        resultSet = statement.executeQuery(sql);

        while (resultSet.next())
        {
            //Always get fields in numerical order, such as 1 then 2 the 3
            info(strFmt('Person Id: %1 -> Person Name : %2', strLRTrim(resultSet.getString(1)), resultSet.getString(2)));
        }
        //Close the connection.
        resultSet.close();
        statement.close();
    }
    else
    {
        error("Failed to log on to the database through ODBC.");

    }
}


Monday, May 15, 2017

Dynamics 365 key shortcuts

If you are fan of using the keyboard when working with D365 for Operations then you might want to know about pressing the CTRL + ‘ to perform an action. Yes that is the single quote or apostrophe symbol. It’s a little hard to see on the label when you hover over the magnifying glass.
What this allows you to do is type in a menu item for the form that you are on. This is handy if you are on for example the customer record and want to see the customer balances you can just type balances in the perform and action box and press enter to open that form. This is handy if you don’t want to take you hands off the keyboard to pick up the mouse.
You can find the details on Microsoft document site.

Thursday, April 6, 2017

Batch script for deleting AUC and KTI files

This post contains a small batch script which deletes all *.auc and *.kti files normally requires when you are willing to clear user caches.

Save this below script in a file and save it as *.bat extension. Execute this file and it will deletes *.auc and *.kti files.

@echo off
cls
setlocal
:PROMPT
SET /P AREYOUSURE=Delete AX User Cache (Y/[N])?
IF /I "%AREYOUSURE%" NEQ "Y" GOTO END

CD %Userprofile%\AppData\Local
Del *.AUC
Del *.KTI

:END
endlocal
Pause

Tuesday, April 4, 2017

Print Management Dialog X++

Sometimes you might need to open up print dialog using X++ code to let user choose what print medium to be used for printing.

This post shows a code sample where sales invoice report is printed using X++ code but before printing Print Management dialog is prompted to choose destination for print as shown below.

Thursday, March 23, 2017

Independent transaction in AX

Sometimes we need to write some data into a database independently on the currently running DB transaction. For example, we want to log some state occurred in the application, however any exception could cause a rollback of the whole transaction, including the log entry. It could look as follows:
LogTable logTable;
;
ttsbegin;
logTable.Message = "Something happens";
logTable.insert();
//some following code in the same transaction throws an exception
throw Exception::Error;
ttscommit;

It can be resolved quite easily. We need to create a separate database connection and possibly our own transaction. The modification of the preceding code would look as follows:

LogTable logTable;
UserConnection connection = new UserConnection();
;
ttsbegin;
//use another connection
logTable.setConnection(connection);
//beginning of the independent transaction
logTable.ttsbegin();
logTable.Message = "Something happens";
logTable.insert();
logTable.ttscommit();
//this exception doesn't affect the logTable entry
throw Exception::Error;
ttscommit;

Thursday, March 9, 2017

Microsoft Dynamics AX Retail

In this post we will highlight components of Dynamics AX Retail. Dynamics AX Retail architecture are divided into two main categories named as Headquarters and Store as shown below.




Let's discuss these categories and their components in details.

Headquarters


Besides having AX essentials components such as Client, AOS, Enterprise Portal and AX Database we have Real-time service and Async Server with message database. The Retail Headquarters component installs runtime components that are required to enable key aspects of Retail functionality, such as the screen layout designer. This component must be installed on the Application Object Server (AOS) computer and on Microsoft Dynamics AX client computers.

Wednesday, March 8, 2017

Combine XPO Tool

The Microsoft Dynamics AX 2012 Combine XPO Tool is a command line program that combines a set of interdependent XPO files into a single XPO. For example, if a team of developers is making code changes to different aspects of an application, they can use this tool to merge those changed files into one XPO file.
As of AX 2012 R2, the Combine XPO Tool is available in the Microsoft Dynamics AX\60\Management Utilities folder. (The beta version of the tool was previously available on InformationSource).

Demonstration

For demonstration purposes I have created two XPO's XPO1 and XPO2 respectively and the output will be a merged XPO containing objects in XPO's file.

XPO 1
XPO 2

The Combine XPO tool generates an XPO file that is a combination of the XPO files in a given folder and any subfolders. It takes the path to the folder and the name of the resulting XPO file as input. For example, if you have XPO files in the C:\MyApplication\ModelA folder, you would use the following commands to create the combined XPO file:
CombineXPOs.exe -XpoDir c:\MyApplication\ModelA -CombinedXpoFile c:\MyApplication\AXModelAFiles.xpo

Results

Merged XPO