Counting the number of records in a QueryRun
March 9, 2010
No comment
When you want to count the number of records that are currently displayed on a form, and you have only one data source, just call the static method countTotal() from the SysQuery-class.
public void executeQuery() { ; super(); info(int2str(SysQuery::countTotal(EmplTable_ds.queryRun()))); }
But when you want to do the same when you joined multiple data sources, you will actually have to loop trough the whole selection. You can do this easily by calling countLoops() on the SysQuery-class. Keep in mind that this has a serious influence on your performance.
public void executeQuery() { ; super(); info(int2str(SysQuery::countLoops(EmplTable_ds.queryRun()))); }
strrep vs. strreplace
March 7, 2010
No comment
In Ax the name of Methods are sometimes (by my opinion) not so clear chosen. For example, when I try to replace a string in ax by typing strrep(..) instead of strreplace(..).
strrep –> repeat a certain string for X times.
strreplace –> replace a certain string.
So please chose clear names for your methods…
About classes
March 6, 2010
No comment
In this post I will talk about classes and what you can do with them.
- Abstract class
When you create a abstract class, you want to ensure that this class can not be instantiated. You wil have to create a sub-class that wil actually use the functionality.
Example:
abstract class MyClass { }
- Extends
When you want to create a new class that inherits methods/properties from a other class, you can ‘extend’ the class. A typical example of a class you will extend from is the ‘RunBaseBatch’-class. When you do this, you will automatically be able to schedule your class.
Example:
class MyClass extends RunBaseBatch { }
- Implements / Interface
Sometimes you want to create a blue-print for new classes by creating a ‘Interface’ class. The you just need to ‘Implement’ the blueprint in you’re new class.
Example:
class MyClass implements SysComparable { }
List of mandatory fields on a table
February 22, 2010
No comment
When you want a list of all the mandatory field on table X, yould check all the properties on the table fields, or you could be lazy and write a small job that does the trick for you. Just replace TableId with your tablenum.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | static void CheckMandatoryFieldsOnTable(Args _args) { DictTable dictTable; DictField dictField; int i; TableId tableId = tablenum(custtable); ; dictTable = new DictTable(tableId); for (i=1 ; i<=dictTable.fieldCnt() ; i++) { dictField = new DictField(tableId, dictTable.fieldCnt2Id(i)); if (dictField.mandatory()) { info(dictField.name()); } } } |
Code Editor – shortcuts
February 20, 2010
No comment
Underneed you find the list of shortcuts I use most in Microsoft Dynamics Ax while developing.
- General (shortcuts I also use outside AX)
- CTRL + S : Save.
- CTRL + C : Copy text to clipboard.
- CTRL + X : Cut text to clipboard.
- CTRL + V : Past text from clipboard.
- CTRL + A : Select all.
- CTRL + LEFT / RIGHT ARROW : Next/Previous word.
- CTRL + SHIFT + LEFT / RIGHT ARROW : Select one word to the left/right.
- CTRL + HOME / END : Go to begin/end of the editor.
- SHIFT + HOME / END : Select text from the cursor to the start/end.
- SHIFT + PAGE-UP / PAGE-DOWN : Select the previous/next page. of the line.
- TAB / SHIFT + TAB : Indent Selection / Remove Indent Selection.
- CTRL + BACKSPACE : Remove previous word.
- CTRL + F : Find.
- F3 : Find Next.
- CTRL + Z / Y : Undo / Redo.
- CTRL (+ SHIFT) + TAB : Next/Previous tab-page.
- Ax specific
- Current Line in the Code Editor
- ALT + L : Select current line.
- CTRL + L : Remove current line.
- Breakpoints
- F9 : Insert / Remove breakpoint.
- SHIFT + F9 : Show all breakpoints.
- CTRL +F9 : Enable / Disable breakpoint.
- CTRL + SHIFT + F9 : Remove all breakpoints.
- Compile / Run
- F5 : run / execute current Job / Class / Form
- CTRL + BREAK : Stop execution.
- Lookup / More Info
- CTRL + ALT + SPACE : Lookup label.
- CTRL + SHIFT + SPACE : Lookup definition (go to the method).
- CTRL + SPACE : Show syntax information.
- Current Line in the Code Editor
And there are more shortcuts. You can find them on MSDN.
Working with numbersequences – On forms
February 18, 2010
No comment
When you want to implement NumberSequences in a Ax form (new numbersequence when you create a record etc.) you can just implement the ‘numberSeqFormHandler’.
Step-by-step: (more…)
Working with numbersequences – New Module
February 16, 2010
No comment
In a previous post I explained how to create a new Number Sequence in a existing module (Working with numbersequences – new NumberSequence). In this post I will explain how you can create a new Number Sequence-module.
I will create a new module called TEST (lack of inspiration).
Step-By-Step: (more…)
Placement of code
February 16, 2010
No comment
When you are programming, you have to think about where placing you’re code. Always try to place you’re code nearest to the source so it can be manipulated easily. For instance code that manipulates tables should be placed in that tables methods.
Best Practice: Try to minimize the x++ code in forms for the following reasons:
- Forms do not support inheritance. You cannot share logic implemented in a form with other application objects.
- The X++ code implemented in forms is always executed on the client. This means that you cannot tune an application by specifying where to execute the code.
Use of ‘like’ in a if-statement
October 13, 2009
1 comment
In Ax it is possible to use the ‘like’ keyword in a if-statement. This would look like this:
1 2 3 4 | if (purchTable.purchId like '09*') { // Do something } |
Using ‘Not Like’ in Ax X++
October 13, 2009
No comment
When you want to use wild-cards in Ax, you can write a SQL statement with a LIKE keyword
1 2 | select firstonly purchTable where purchTable.purchId like '09*'; |
When you want to have all the other records (not like), in X++ SQL-statements you have 3 possibilities:
1.!LIKE :
1 2 | select firstonly purchTable where !(purchTable.purchId like '09*'); |
2. notExists join :
1 2 3 | select firstonly purchTable notExists join refPurchTable where purchTable.purchId == '09*'; |
3. Query-object :
1 2 3 4 5 6 7 8 9 10 11 | Query query = new Query(); QueryRun queryRun; ; query.addDataSource(tableNum(PurchTable)).addRange(fieldNum(PurchTable, PurchId)).value('!09*'); queryRun = new QueryRun(query); if(queryRun.next()) { purchTable = queryRun.get(tableNum(PurchTable)); print purchTable.PurchId; } pause; |




