Iterating over any table

2019-08-05 01:40发布

I just started new job where they use dynamics ax 2009. I am new to this technology.

Is there a way in x++ to iterate over any table? I don't know where the data comes from, it's lenght nor field count.

What I mean by that is I need a function that would behave like this

void convert(Table anyTable) 
{
    int i=0; 
    int k=0;
    ;

    for(i; i < anyTable.Lenght; i++)
    {
        for(k; k < anyTable[i].Count; k++) 
        {
            //some xml processing 
        } 
    }
} 

(By Table i mean some kind of parent of all tables). And that basically is my question - is there a parent of all tables or something of such sort that can help me achieve something like this?

I am sorry for formatting, im typing this from mobile device

3条回答
成全新的幸福
2楼-- · 2019-08-05 02:37

Check out xml() method on Common class, it may help generate your XML representing the current record.

查看更多
乱世女痞
3楼-- · 2019-08-05 02:38

The Common table is the base class for all tables. It does not contain any data. It is primarily used in X++ code to refer to any table in a polymorphic way. Please check Dictionary classes to solve your issue:

void convert(Common _common)
{
    DictTable       dictTable;
    FieldId         fieldId;
    anytype         value;
    ;

    dictTable = new dictTable(_common.TableId);

    if (dictTable)
    {
        while select _common
        {
            fieldId = dictTable.fieldNext(0);

            while (fieldId)
            {
                value = _common.(fieldId);

                //do processing

                fieldId = dictTable.fieldNext(fieldId);
            }
        }
    }
}
查看更多
闹够了就滚
4楼-- · 2019-08-05 02:41

See this answer. It involves use of class Dictionary and DictTable for reflection.

查看更多
登录 后发表回答