Smart projects

May 21, 2010 No comment

Every Ax developer tries to group their code from one defect or one analysis in one project. Sometimes you try to maintain the AOT structure in that project through groups (don’t forget to set the property projectGroupType). What some developers don’t know is that project-groups have a property GroupMask. Here you can fill in a prefix or part of a word and Ax will automaticly search through the AOT for objects that match this GroupMask. This system will also automaticly maintain itself.

Step-By-Step:
Go to your project and change the GroupMask property of a Group

Now when you save this and look at your project you will see the following:

Conclusion: Ax searches the AOT looking for all objects that matches the ‘projectGroupType’ and the ‘groupMask’.

Tip: When you set the GroupMask-property to ‘Tutorial’, Ax will look for all tutorials in the AOT. I have made a export of the project-structure, so you can have this output quicker. You can download this here.

System tables – part1

May 3, 2010 No comment

In this post I will talk about some Ax kernel tables that are automatically created after the setup at the first run of Ax. They are typically company independent (no DataAreaId) and contain some valuable information about AX.

You can find the tables I wil discuss under the AOT –> System Documentation –> Tables.

It is not easy to find info about these tables, but I hop this helps you all a bit.

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

Moving DB-objects to other layers … without losing data

February 14, 2010 No comment

Most of us have already been confronted with the problem of tables being inserted in the wrong layer, and when they already contain data it is very difficult to transfer these objects to the correct layer without losing data.

I found the following article on Axaptapedia that helps you with this issue: http://www.axaptapedia.com/Move_DB_objects_to_another_layer

Changing AOT properties from code

June 23, 2009 No comment

When you want to it is possible to change AOT properties from code.

The first you need to do, is finding the treenode you want to modify:

1
2
3
4
5
#AOT
#Properties
TreeNode                        node = TreeNode::findNode(#TablesPath);
;
node = node.AOTfindChild("SysUserInfo");

When you want to get a property you can simply check this by using the method AOTGetProperty. In the macro Properties you have a macro for evry property.

1
info(node.AOTgetProperty(#PropertyCreatedby));

When you want to change the property you use the method AOTSetPropery.

1
node.AOTsetProperty(#PropertyCreatedby, #PropertyValueYes);

Now you just have to save the changes you made by calling the save method and releasing the memmory held by the TreeNode. The garbage collector cannot clean up objects it self.

1
2
3
node.AOTsave();
node.treeNodeRelease();
node = null;

So if you put all this code in a job you get:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
static void JeDoe_testTreeNode(Args _args)
{
    #AOT
    #Properties
    TreeNode                        node = TreeNode::findNode(#TablesPath);
    ;
    node = node.AOTfindChild("SysUserInfo");
    info(node.treeNodePath());
    info(node.AOTname());
 
    info(node.AOTgetProperty(#PropertyCreatedby));
 
    node.AOTsetProperty(#PropertyCreatedby, #PropertyValueYes);
 
    node.AOTsave();
    node.treeNodeRelease();
    node = null;
}

Extra:

You can also Create/Modify/Delete code in mothdes from code. For doing this you wil need to use the variable MemberFunction. You simply Find the TreeNode-path from the method you want to modify and put it into the MemberFunction variable. The you can get/set the source code with AOTGetSource/AOTSetSource. After changing the code you just need to save and compile with AOTSave & AOTCompile.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
TreeNode                        dataSourceNode;
TreeNode                        formNode;
MemberFunction                  method;
str                             dataSourceMethodPath    = ...; // Path to the method you want to modify
str                             formPath                = ...; // Path to the form you want to modify
;
formNode            = TreeNode::findNode(formPath);
dataSourceNode      = TreeNode::findNode(dataSourceMethodPath);
if(dataSourceNode &amp;&amp; formNode)
{
    method          = dataSourceNode.AOTfindChild(#Active);
    if (!method)
    {
        dataSourceNode.AOTadd(#Active);
        method      = dataSourceNode.AOTfindChild(#Active);
    }
    method.AOTsetSource(method.AOTgetSource() + "// Some comment", false);
    formNode.AOTsave();
    formNode.AOTcompile(1);
}