2007-12-18

Integration AX with side applications

The Microsoft Business Connector is the way to integrate AX with outside world. It allows the programmer to leverage existing Microsoft Axapta functionality in his favorite programming language. At the other hand AX has one powerful feature: enumerators. An enum is a list of literals, which can be used throughout the development environment in MorphX. Really, in MorphX using enumerators very simple, e.g.:
SalesStatus status; //Order status as to delivery and invoicing;
if(status == SalesStatus::Invoiced)
{
...
}
There are two advantages: it is an easy way to make an overall change in the system; the code is easier to read; Unfortunately, side application nothing "knows" about this AX feature. And we need to use constants directly in code!
if(status == 3)//SalesStatus::Invoiced)
{
...
}
Let's try to instruct side applications enums feature. The idea consists in asking AX directly what does construction SalesStatus::Invoiced mean. To do this I've developed new DEV_DictTable class with some methods.
// Created by GRR on 18.07.2007 for AX Connector
class DEV_DictTable
{

}

// Returns constant, where _enumName is enum's name; _enumSymbol - literal
int getEnum(identifierName _enumName, str 
_enumSymbol)
{
        return new DictEnum(enumName2Id(_enumName)).symbol2Value(_enumSymbol);
}
An example how to use this class:
dict = AX.CreateObject("DEV_DictTable"); // A reference at our class
SalesStatus_Invoiced = dict.Call("getEnum", "SalesStatus", "Invoiced"); // here we store our constant 3
//And now we may use SalesStatus::Invoiced in side application code -->
if(status == SalesStatus_Invoiced){
...
}// <--
There are some methods in DEV_DictTable class to improve integration's flexibility:
// gets enum label according enum name and specific value
str getEnumLabel(identifierName _enumName, int _value)
{
        return new DictEnum(enumName2Id(_enumName)).value2Label(_value);
}

// gets fieldId according Axapta's tableName and fieldName
FieldId getFieldId(str tableName, str fieldName)
{
        FieldId fieldId;
        DictField dictField;
        TableId tableId;
        ;

        tableId = new SysDictTable(tableName2Id(tableName)).id();
        dictField = new DictField(tableid, fieldName2Id(tableId, fieldName));
        fieldId = dictField.id();
        return fieldId;
}
// gets tableId according Axapta's tableName
TableId getTableId(str tableName) {         SysDictTable sysDictTable;         TableId tableId;         ;         sysDictTable = new SysDictTable(tableName2Id(tableName));         tableId = sysDictTable.id();         return tableId; }

1 comment:

Jaffar said...

Hi

Is there any way I can create a report which lists all the Enums with Labels and Integer values)(Constants)?

I'm using Ax2009.

Thank you
Jaffar