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");
    }

}

Tuesday, October 7, 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;
}

Thursday, January 23, 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


Thursday, December 5, 2013

Enable/Disable Fact boxes, Preview Panes in AX2012 UX

In Microsoft Dynamics AX 2012, if you want to disable factboxes/preview panes across application then you can do so.
It's not recommended to do this activity but this will help in troubleshooting performance issues assoicated with opening forms in ax2012 by controlling 'Timeout' parameter as below.

Go to ->System Administration->Setup->Client performance options 

Visit  Ax2012-client-performance-options for detailed explaination by Ax performance team.

Thanks axperf team :)

reference from : http://learnax.blogspot.in/2012/02/enabledisable-fact-boxes-preview-panes.html

Wednesday, October 23, 2013

Sequence of methods in form and table in AX


Form:
Sequence of Methods calls while opening the Form
Form — init ()
Form — Datasource — init ()
Form — run ()
Form — Datasource — execute Query ()
Form — Datasource — active ()
Sequence of Methods calls while closing the Form
Form — canClose ()
Form — close ()
Sequence of Methods calls while creating the record in the Form
Form — Datasource — create ()
Form — Datasource — initValue ()
Table — initValue ()
Form — Datasource — active ()
Sequence of Method calls while saving the record in the Form
Form — Datasource — ValidateWrite ()
Table — ValidateWrite ()
Form — Datasource — write ()
Table — insert ()
Sequence of Method calls while deleting the record in the Form
Form — Datasource — validatedelete ()
Table — validatedelete ()
Table — delete ()
Form — Datasource — active ()
Sequence of Methods calls while modifying the fields in the Form
Table — validateField ()
Table — modifiedField ()

Table:
When you press CTR+N
initValue()->

When you change data in a field
validateField() -> validateFieldValue() -> ModifiedField() -> ModifiedFieldValue()

When you close the table after entering some data
validateWrite() – > Insert() -> aosValidateInsert()

When you Save the Record for the first time
validateWrite() ->Insert() – > aosValidateInsert()

When you modify the record and saving
validateWrite() -> update() – > aosValidateUpdate()

When you delete the record
validateDelete() -> delete() -> aosValidateDelete()


reference : http://axvuongbao.blogspot.in/2013/09/sequence-of-methods-in-form-and-table.html