Monday, December 22, 2014

How to import Contoso Demo Data to Dynamics AX 2012 R3

The setup contoso demo data for Dynamics Ax 2012 R3 is different from previous version. I remember, I used .dat file to load demo data into Dynamics Ax 2012 R2. Now DynamicsAX2012R3DemoData.exe available partner Resource.
03-Demo setup
DynamicsAX2012R3DemoData.exe extracted files round 15 GB. Extracted folder contains three types of files. According to MSDN
  • Xml (A bcp data file that contains table data. Columns are separated by #|EOC|#. Rows are separated by #|EOR|#\n.)
  • Out (A bcp data file that contains the table metadata (column descriptions).
  • OutModel (This metadata includes all names and IDs of the table and its fields. This file also includes the elementType attribute, which stores the names and IDs of any Microsoft Dynamics AX tables, classes, or extended data types that are referenced by the table)
Installation of Test Data Transfer Tool:
The MSDN Described The Import export with Test Data Transfer Tool (beta) as follow.
IC665318


Test Data transfer Tool is available on partner resource.
Go on following link

04-InformationSource

On login I found download page
05-download

There will be zip file downloaded.  On running I found following installation wizard.

11-Beta Setup

12-Beta Setup next

Setup run will be generated as following
06-folderDetail

Import Data Into Dynamics Ax 2012 R3 instance:
And import MetaDataXMLGenerator.xpo in dynamics Ax.
07-ImportGenerator

This xpo imports results a job inside job node under AOT.

08-Job



This job will generate Metadata.xml. This Metadata.xml will be created in window temporary folder.
Path of file in metadata.xml can be get from infobox which will appear after successful run of job.
13-metaFile

if you lost infobox,You can get temporary folder path with following command echo %temp%. where you can get Metadata.xml
Copied metadata.xml into [list] folder of test tool Data folder. If it already exists then overwrite it.
15-copy meta data

Now open command prompt. Go to directory where Test import tool is extracted.
Run the following command
DP.exe IMPORT “E:\Contoso_Demo_Data\DynamicsAXR3DemoData” MicrosoftDynamicsAx

Please update path according to your installation.
09-Command Prompt

After running the command, you will find following window which describe the process by remaining table to number data, and number of error occurs during import.
10-Remaining

This process takes hours and hours with respect to your machine. After completion, I found demo data inside my dynamics Ax 2012 R3.

14-DataAppear

Thanks to Ali

Friday, December 19, 2014

List all the objects from the project node in AX 2012

Hi MSDAX technical consultants,

In Microsoft dynamics AX 2012 to find all the objects from the projects you can use following code. 

static void listAllObjectosFromProject(Args _args)
{
    #define.Shared("Shared")
    
    ProjName            projName = "Test";
    ProjectListNode     list = infolog.projectRootNode().AOTfindChild(#Shared);
    TreeNodeIterator    ir = list.AOTiterator();
    ProjectNode         pnProj;
    ProjectNode         pn = list.AOTfindChild(projName);

    void searchAllObj(projectNode rootNode)
    {
        #TreeNodeSysNodeType
        TreeNode          childNode;
        TreeNodeIterator  rootNodeIterator;
        ;

        if (rootNode)
        {
            rootNodeIterator = rootNode.AOTiterator();
            childNode = rootNodeIterator.next();
            while (childnode)
            {
                if (childNode.treeNodeType().id() == #NT_PROJECT_GROUP)
                {
                    searchAllObj(childNode);
                }
                else
                {
                    //info(strfmt("Group :%1 - Object: %2", rootNode.AOTname(), childNode.AOTname()));
                    info(strfmt("%1", childNode.AOTname()));
                }
                childNode = rootNodeIterator.next();
            }
        }
    }
    ;

    if (pn)
    {
        //info(strFmt("Project %1:", projName));
        pnProj = pn.loadForInspection();
        searchAllObj(pnProj);
        pnproj.treeNodeRelease();
    }
    else    
    {
        info("Projet objects");
    }

}

Monday, October 6, 2014

Create Menuitem at runtime or through X++ and set properties

Hi Guys,

Here is the example of creating menuitem through X++ code.


static void CreatingMenuItemRutime(Args _args)
{
    
    TreeNode          treeMenuItem;
    str                    menuName = "TestOutputMenuItem";
    str                    properties;
    #AOT
    #Properties
    ;
    
    treeMenuItem = TreeNode::findNode(#MenuItemsOutputPath);
    treeMenuItem.AOTadd(menuName);
    
    treeMenuItem = treeMenuItem.AOTfindChild(menuName);
    properties = treeMenuItem.AOTgetProperties();
    
    properties = setProperty( properties, #PropertyLabel,'Sales Report');
    properties = setProperty( properties, #PropertyObjectType, 'Class');
    properties = setProperty( properties, #PropertyObject,'SalesFormLetter');
    properties = setProperty( properties, #PropertyParameters, 'ReportX1\\Report');
    
    treeMenuItem.AOTsetProperties(properties);
    
    treeMenuItem.AOTsave();
    print "New Menuitem is created under output menuitem";
    pause;
}

Wednesday, January 22, 2014

How to: Connect to an External Database from X++ Code [AX 2012] [AX 2009]

Create a DSN


To create a Data Source Name (DSN) go to Administrative Tools > Data Sources (ODBC).
Create the DSN on the tier where the X++ code will call the DSN from. This will be either on the client computer or on the Application Object Server (AOS) computer.
NoteNote
Ongoing maintenance is simpler if the DSN is created on the AOS tier.
X++ Code Example with ODBC


The following X++ code example uses ODBC to connect to an external database. The code example assumes that you have already created the DSN in Windows.
// X++, Main method in a class.
static public void Main(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("dsnName");
    loginProperty.setDatabase("databaseName");

    //Create a connection to external database.
    odbcConnection = new OdbcConnection(loginProperty);

    if (odbcConnection)
    {
        sql = "SELECT * FROM MYTABLE WHERE FIELD = "
            + criteria
            + " ORDER BY FIELD1, FIELD2 ASC ;";

        //Assert permission for executing the sql string.
        perm = new SqlStatementExecutePermission(sql);
        perm.assert();

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

        //Cause the sql statement to run,
        //then loop through each row in the result.
        while (resultSet.next())
        {
            //It is not possible to get field 3 and then 1.
            //Always get fields in numerical order, such as 1 then 2 the 3 etc.
            print resultSet.getString(1);
            print resultSet.getString(3);
        }

        //Close the connection.
        resultSet.close();
        statement.close();
    }
    else
    {
        error("Failed to log on to the database through ODBC.");
    }
}

32 Bit and 64 Bit Windows Operating System

The preceding code example can run on either the client tier or the server tier. The following table shows how the operating system architecture affects the choice of tier.

32 bit Windows
64 bit Windows
Client tier (MorphX)
Runnable.
Not runnable.
Server tier (AOS)
Runnable.
Runnable.
Consider adding the server keyword to the declaration of the Main method.
If you want to do Insert/Update operation through this code then you must use following code.

int      _returnId;

sql = " Your insert / Update Query"
 //Prepare the sql statement.
statement = odbcConnection.createStatement();
_returnId = statement.executeUpdate(sql);

reference :1. Microsoft Documentation MSDN 2. ArtofCreation 3. GalaxyofDynamics