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…)

Maximum value RecId

February 15, 2010 No comment

Did you ever wonder what the maximum value of a RecId was?

In Ax3.0 it is pritty simple. You know that the RecId was a int value and with the function ‘maxInt()’, you get the value.

In Ax4.0 and higher, the RecId is changed from a regular int to in64. There is no such function as ‘maxInt64()’ so you cant use this. In the ‘Global’, I found a method called ‘maxRecId()’.
So you just call this method and you will see that the maximum value of a RecId is 9223372036854775807 (I hope I didn’t mistype) or 2^63-1.

Line Number

February 13, 2010 No comment

When you want to create a table were you want to remain the position of the records you create (like the lineNum field on the SalesLine), you just need to define a field on your new table as a ‘CounterField‘.

Step-by-step: (more…)

Select a record from a table when you only have the tableId

July 16, 2009 1 comment

The following code can provide you a generic way to update a table when you only have the tableId.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public Common findRecord(TableId _tableId, RecId _recId, Boolean _forUpdate = false)
{
    Common      common;
    DictTable   dictTable;
    ;
    dictTable = new DictTable(_tableId);
    common = dictTable.makeRecord();
 
    common.selectForUpdate(_forUpdate);
 
    select common
    where common.RecId == _recId;
 
    return common;
}

If you want, you can even update fields in this common record. You can Access/edit these fields by using their Name or FieldNum. The method below will update a specific field in a table.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public void updateValue(TableId _tableId, RecId _recId, str _field, AnyType _value)
{
    Common      common;
    Int         fieldId;
    ;
    ttsbegin;
    common = findRecord(_tableId, _recId, true);
    fieldId = fieldname2id(_tableId,_field);
 
    if (fieldId && _value)
    {
        common.(fieldId) = _value;
        common.update();
    }
    ttscommit;
}

Using FilePath on a form

June 25, 2009 1 comment

When you want a filebrowser on your form and you only added a field that extends from the Extended Data Type FilePath, you wil get a stack-trace/error message when you click on the folder icon. Don’t panic, there is nothing wrong with your AX. Like the error explains you just need to provide the form with the method filePathLookupTitle.

error_formRun_filePathLookupTitle

1
2
3
4
public LabelString filenameLookupTitle()
{
    return "Select Import File";
}

Normally this should solve your problem.

There are some more methods you can add to control the file lookup:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public LabelString filenameLookupFilename()
{
    return "";
}
 
public FileNameFilter filenameLookupFilter()
{
    FileNameFilter filter;
    filter = ['All FIles','*.*'];
    return filter;
}
 
public LabelString filenameLookupInitialPath()
{
    return "";
}
 
public LabelString filePathLookupTitle()
{
    return "Select Document Path";
}

Working with numbersequences – new NumberSequence

May 5, 2009 1 comment

When you want to create a new NumberSequence in AX you have to do the following steps:
1. Create a new Extended Data Type (EDT). Often this EDT extends from num. (this step is not mandatory, but it is a best practice)

2. Discide in witch module this new Number Sequence Reference (classes NumberSeqReference_…) should be included and find the corresponding NumberSeqReference class. (ex. module sales –> NumberSeqReference_SalesOrder)

3. The loadModule() method shows a number of blocks of code, which creates records in the table NumberSequenceReference.

4.Copy a block and change the following fields:
* DataTypeID is the type Id of the new data type.
* referenceLabel is the description shown in the left column of the Number sequence tab on the parameters form.
* referenceHelp is the longer description of the reference shown in the top part of the Number sequence tab of the parameters form.
* sortfield defines the sequence that the references are displayed on the Number sequence tab of the parameters form.
* The wizard fields are default values when using the wizard to create a numbersequenceexample:

1
2
3
4
5
6
7
8
9
numRef.DataTypeId = typeId2ExtendedTypeId(typeid(NewType));
numRef.ReferenceLabel = literalstr("@...");
numRef.ReferenceHelp = literalstr("@...");
numRef.WizardManual = NoYes::No;
numRef.WizardAllowChangeDown = NoYes::No;
numRef.WizardAllowChangeUp = NoYes::No;
numRef.SortField = #;
 
this.create(numRef);

5. Create a static method on the parameter table that will be used to retrieve the reference. These methods usually start with “numref”.
example:

1
2
3
4
static client server NumberSequenceReference  numRefNewType()
{
return NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(NewType)));
}

Type of Anytpe enum

April 14, 2009 No comment

Normaly you try to avoid using AnyType variables, but sometimes you are forced to use them. When you use a AnyType enum and you want to cast it to it’s actual data type, be sure you cast it to the right type to prevent stack-traces. You can get the enumId from a AnyType-enum by using the DictEnum::value2id(AnyType _value) -function. Then you can compare it with the enumnum(EnumType) to check if it is the right type.

In code this check could look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
static void testAnyTypeEnumCasting(Args _args)
{
    DocumentStatus  docStatus;
    Anytype         any = DocumentStatus::Invoice;
    ;
    switch (DictEnum::value2id(any))
    {
        case enumnum(DocumentStatus) :
            docStatus = any;
            break;
        case enumnum(...) :
            ...
    }
}