Search code examples
axaptax++dynamics-ax-2009

Iterating over any table


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


Solution

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