Skip to main content

Posts

Showing posts from May, 2012

"Error when executing direct SQL – SqlStatementExecutePermission”

While accessing SQL statements within AX world I came across an error which was really time consuming for me to get rid of. I created a method like this; It got failed while executing statement and gave following error " Error when executing direct SQL – SqlStatementExecutePermission” on line  resultSet = statement.executeQuery(sql); SOLUTION: You can solve this issue easily, if you use the method marked as server static and call this method from the display method.  

Dynamics AX 2012: "Precision lost" warning message

This post is copied from  Peter Villadsen    blog and I thought to share it on my blog too. It really helped me a lot. A question came up at today's webinar where a developer had a (presumably legitimate) reason to cast a real value into an integer value. The X++ language does not allow explicit casting (there's no support for it in the language), but the compiler will do its best to satisfy the user and do the conversion on its own. In this case, however, it issues a warning message, lest this is not what the user wanted. One solution is to use the anytype type to hold the vaue for conversion and then using the any2int function, as shown below: static   void  Job47(Args _args)  { real r =  3.13 ; int  i = r;       // Warning is issued here  anytype a; a = r;           // Assign to an anytype variable...  i = any2int(a);  // ... and back into an int  print r; ...

Code for Traverse between Tables and all the fields

With reference of Bineet's blog here I found the code for Traverse between tables and all the fields. //Travese between tables and for each table traverse between all the fields static void TeeNode_traverse(Args _args) {     TreeNode            treeNode, treeNodeTable;     TreeNodeIterator    iterator;     void traverseFields(TreeNode _treeNode)     {         TreeNode parentNode;         parentNode = _treeNode.AOTfindChild(‘Fields’);         //treeNodeTable = _treeNode.AOTfirstChild();         iterator = parentNode.AOTiterator();         parentNode = iterator.next();         while(parentNode)     ...

How to get table name and number of records in each table in AOT

Today, I came across a requirement to find out the name of each table in AOT along with the number of records for each table. Here is the code to achieve this functionality; void getTableNameRecordCount(Args _args) {     #AOT Name name;     NumberOf recordCount;     TreeNode treeNode;     SysDictTable sysDictTable;     ;     treeNode = TreeNode::findNode(#TablesPath);     treeNode = treeNode.AOTfirstChild();     while (treeNode)     {         name = treeNode.AOTname();         sysDictTable = SysDictTable::newTableId(treeNode.applObjectId());         recordCount = sysDictTable.recordCount(false);         if (recordCount)         info (strfmt("@SYS26868", name, recordCount));         treeNode = treeNode.AOTnextSibling();     } }

CRUD operation in Dynamics AX 2009 through .Net business connector

Friends, rather going into more details about "How to's" of accessing Dynamics AX through .Net, my main objective is to share my experience of performing CRUD operations in Dynamics AX 2009 through .Net BC. Here is a sample code;     // CREATE OR INSERT SAMPLE     // Create the .NET Business Connector objects.     Axapta ax;     AxaptaRecord axRecord;     string tableName = “AddressState”;     try     {         // Login to Microsoft Dynamics AX.         ax = new Axapta();         ax.Logon(null, null, null, null);         // Create a new AddressState table record.         using (axRecord = ax.CreateAxaptaRecord(tableName));         {             // Provide values for each of the AddressState record fields.             axRe...

How to reuse table Id in Dynamics AX

Sometime we created tables just for testing purpose within AOT and later on we delete these tables. In such cases we don't care about the IDs which are created for each table. There is a way to use these system generated IDs for other newly created tables.  You can do this by following steps; 1.      Export the table with its current id. 2.      Delete the table 3.      Edit the xpo file and change the id to what you want 4.      Import the xpo file with the id option checked.  As long as the id is not used by something else, then it should get imported with that id.

Dynamics AX 2009: How to retrieve table properties

Here is the sample code to retrieve table properties in Dynamics AX 2009. static void TableProperties(Args _args) {     Dictionary                      dictionary;     TableLabel                      tableLabel;     SysdictTable                    dTable;     TreeNode                        Tnode;     ;         //initilize the data dictionary     dictionary = new Dictionary();     // Replace _tableId parameter with the actual table id     dTable = new SysDictTable(_tableId);     // initilize the tree node to traverse each property of the table     tNode = dTable.treeNode();     // Replace "Label" with any property name of th...