Posts tonen met het label Extended Data Type. Alle posts tonen
Posts tonen met het label Extended Data Type. Alle posts tonen

dinsdag 31 augustus 2010

Retrieve label of EDT

How to get the label of an EDT?

See \Classes\DialogField\init
setting the label:
o.label(dictType.label(f));
with the dictType being:
dictType = new DictType(xtype);
and xtype being:
xtype = type >> 16;


Why do we have to right shift 16?
see \Classes\SysDictField\new
there you find a left shift 16
and global::fieldExt2Id does:
return (fieldExtId & 0xffff);

Also see http://www.eggheadcafe.com/software/aspnet/29515376/addfield-parameters.aspx
exerpt:
typeid() function gives you the id of a type. For eg:
you can try the following code in a job:
static void job1()
{;
print typeid(custAccount);
pause;
}
This will print out 6488075. In the AOT if you check up the ID of CustAcount
it is 99. But the above number that get from typeid function is a
combination of the ID in the AOT and the flag indicating that it is a user
type. The upper 16 bits contain the ID from the AOT (99)and the lower 16
bits contain the flag that it is a user type (11)
6488705 == (99 << 16 | 11)


Example:
public boolean validate(Object calledFrom)
{
    boolean ret;
    ToDate todate;
    dictType dictTypeLocal;
    ;


    ret = super(calledFrom);


    if (!toDate)
    {
        dictTypeLocal = new dictType(typeId(todate) >> 16);
        ret = checkfailed (strfmt("@SYS110217", dictTypeLocal.label()));


    }
    return ret;
}


Example - short version:
static void Job8(Args _args)
{
;
info(new dictType(typeId(ToDate) >> 16).label());
}



In Global Class:
public static LabelString aduTypeLabel(extendedTypeId _typeId)

{
;
return new dictType(_typeId >> 16).label();
}


Also (this example is a static method on ConfigTable):
static FieldLabel aduLabel()

{
;
return new SysDictType(extendedtypenum(ConfigId)).label();
}

dinsdag 10 augustus 2010

num2str - decimals based on EDT

num2str function with the number of decimals based on the property of an Extended DataType

Code based on Mirko Bonello's work: http://dynamicsax-dev.blogspot.com/2009/02/getting-number-of-decimal-places-for.html


str num2strEdt(
    real _number,           //The real number to convert to a string
    int _character = 0,     //The minimum number of characters required in the text.
    ExtCodeValue _edt,      //The EDT to be used as basis for required number of decimal places.
    int _separator1 = 2,    //DecimalSeparator
    int _separator2 = 0)    //ThousandSeparator
{
    #DEFINE.AUTO('Auto')
    // http://www.rgagnon.com/pbdetails/pb-0181.html
    #DEFINE.LOCALE_USER_DEFAULT(1024)
    #DEFINE.LOCALE_ICURRDIGITS(25)

    #AOT
    #PROPERTIES
    #WinAPI // Used for regional settings

    TreeNode treeNode;
    int decimalPlaces;
    ;
    treeNode = infolog.findNode(#ExtendedDataTypesPath + '\\' + _edt);
    if (!treeNode)
        return strfmt("%1", _number);

    if (findproperty(treeNode.AOTgetProperties(),#PropertyNoOfDecimals) == #AUTO)
    {
      // get the number of decimals from the regional settings
      decimalPlaces = str2int((WinAPI::getLocaleInfo(#LOCALE_USER_DEFAULT,   #LOCALE_ICURRDIGITS)));
    }
    else
    {
      // get the number of decimals set by the developer in the property inspector
      decimalPlaces = str2int(findproperty(treeNode.AOTgetProperties(),#PropertyNoOfDecimals));
    }

    return num2str(_number, _character, decimalPlaces, _separator1, _separator2);
}

usage example:

info(strfmt("%1", num2strEdt(20.34, 0, (identifierstr(myEDT)))));

dinsdag 6 oktober 2009

Table relation or Extended Data Type relation: which one is used?

Extended Data Type (EDT) definition:












Table Definition:



















Field ADUEmplInventBuyerGroup.ItemBuyerGroupId  has ETD=ItemBuyerGroupId.

Table Browser for ADUEmplInventBuyerGroup: (in dutch)























When we right-click on field ItemBuyerGroupId > Go To Main Table Form.
Which table will be openened?
Will AX follow the EDT defined on the field and open table InventBuyerGroup?
Or will AX choose a table defined in the relations on ADUEmplInventBuyerGroup (InventBuyerGroup or VendTable) ?

The answer is:
AX always first looks at the relations defined on the table, and then on the EDT.
If however there is an ambiguous definition (= multiple relations are defined on the field), then AX follows the relation on the EDT.

In a flowchart: