Search code examples
x++dynamics-ax-2012-r2

How to insert into a table field with value from a display method dependent of string


as you might know, this is a nice way to dynamically set values to fields.

myTable.(fieldName2Id(myTable.TableId, fieldNameStr)) = "This value";
myTable.insert();

What I am wondering about is if there is any way to do it in a similar fashion with display methods, just dynamically get the values from them?

If i have the Display method name (i.e. itemName()) how can I do this...? something like this to demonstrate how i think:

methodNameStr = "ItemName";  
myTable.myField = mytable.(methodName2Id(myTable.TableId, methodNameStr));
myTable.insert();

Solution

  • Use DictTable.callObject(medhodName, buffer).

    Common myTable;
    DictTable dt;
    
    //<SampleOnly>
    str methodNameStr = "itemDescriptionOrName";
    InventTable tmpTab;
    
    select firstOnly tmpTab;
    myTable = tmpTab;
    //</SampleOnly>
    
    dt = new DictTable(myTable.TableId);
    dt.callObject(methodNameStr, myTable);
    
    info(strFmt("%1", dt.callObject(methodNameStr, myTable)));