Loop all tables

September 16, 2010 1 comment

There is a simple trick to loop all tables that are available in Ax. Just use the Dictionary-class that contains all information about tables.

Small example to list all tablenames + their corresponding Id.

1
2
3
4
5
6
7
8
9
10
static void JeDoe_listTables(Args _args)
{
    Dictionary  dictionary = new Dictionary();
    int         i;
    ;
    for (i=1 ; i<=dictionary.tableCnt() ; i++)
    {
        info(strfmt('%1;%2', dictionary.tableCnt2Id(i), tableid2name( dictionary.tableCnt2Id(i) )));
    }
}

When you combine this with a DictTable / DictField-object, there are lots of possibilities.

Dialog Extended

May 12, 2010 No comment

One of my colleagues (Koen Dedecker) was looking for a way to prevent user interaction with other forms while a certain dialog is shown. After some research he found the solution on the blog Dynamics AX tools and tutorials from Vanya Kashperuk. A few years ago (2007) he made a simple extension of the dialog class that makes this possible. You can find more information and download some code samples on http://kashperuk.blogspot.com/2007/06/3-dialog-extensions.html.

The trick is actually simple:

Now when you make a new instance of the dialog class just set the value of the parmShowModal() to true. From now on this dialog will stay on top.

Batch job performance boost

April 22, 2010 No comment

Did you ever have trouble with the performance of your batch-job? Well maybe this small trick can shorten the time your batch runs.

The big idea: Try to split up your gigantic batch in smaller pieces. Launch a batchjob that produces many smaller batchjobs (tasks) that can handle a subset of the data you need to process. For example you can create a batch that creates a batch with sub-tasks for each company.

How do you plan a batch from code?

1
2
3
4
5
6
7
8
9
10
11
12
BatchHeader batHeader;
BatchInfo batInfo;
TstRunBase rbbTask;
;
rbbTask = TstMyBatch::construct();
batInfo = rbbTask.batchInfo();
batInfo.parmCaption("MyBatch");
batInfo.parmGroupId("");
batHeader = BatchHeader::construct();
batHeader.addTask(rbbTask);
batHeader.save();
info(batInfo.parmCaption());

You can download a quick example I made. This is a job you can schedule and it will produce a new Batch job with a task for each company when you don’t select a company while shedualing (Class_TstRunBase.xpo). I hope this can help you.

Schedule the batch:

The result:

Tip for overriding methods

April 19, 2010 3 comments

There is a simple and generic way to force overriding a method you created. To do so you just need create your new method and place a ‘throw error’ statement in it. To finish you can add the static method missingOverride from the error class and the funcName() to your error. Now when this method is called or the super() in you child class is called, you will get a error that you need to override your method.

public identifiername myMethod()
{
    throw  error(Error::missingOverride(funcName()));
}

When you use this peace of code you will get the following error:

Note: The error-class also has some other usefull static methods like: missingFormActiveBuffer, missingOverload, missingOverride, missingParameter, missingRecord and my favorite wrongUseOfFunction

Create class from code

March 11, 2010 No comment

Did you know that you can build/modify classes from code? It is actually not so hard, just use the ClassBuild-class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
static void JeDoe_testClassBuild(Args _args)
{
    ClassBuild  classBuild;
    ClassNode   classNode;
    Str         myCode;
    ;
    myCode =
@"
static void Main(Args _args)
{
    ;
    info('Hello World!');
}
";
 
    classBuild = new ClassBuild("MyTest", false);
    classBuild.addMethod("Main", myCode);
 
    classNode = classBuild.classNode();
    classNode.AOTcompile();
    classNode.AOTrun();
}

The sample above will create a new class MyTest with a ‘Hello World’ Main-method and will actually save compile/save the code in the AOT and then run it. Cool?

Note: The SysDictClass/SysDictMethod-class can also help you creating proper classes and methods. Maybe I’ll blog about this later.

About classes

March 6, 2010 No comment

In this post I will talk about classes and what you can do with them.

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
{
}

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
{
}

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
{
}