“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; print i; pause; } This should be packaged into a function, maybe called int RealToInt(real arg). Another way would be doing the conversion in managed code (through the System.Convert::ToInt32(object) method), but the performance will not be as good because of the marshalling that needs to take place. I hope this helps.
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) { //treeNodeTable = treeNodeTable.AOTfirstChild(); parentNode = iterator.next(); } } ; treeNode = TreeNode::rootNode(); treeNode = treeNode.AOTfirstChild(); treeNodeTable = treeNode.AOTfindChild(‘Tables’); treeNodeTable = treeNodeTable.AOTfirstChild(); while(treeNodeTable) { traverseFields(treeNodeTable); treeNodeTable = treeNodeTable.AOTnextSibling(); } }
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(); } }