Thursday, August 5, 2010

Calling method at runtime

In Dynamics AX, you can decide at runtime whether you need to call a method or not. See example below in which the find method of CustTable is called at runtime.

static void invokeMethodOnRunTime(Args _args)
   DictTable dictTable = new DictTable(tablenum(CustTable));
   CustTable custTable;
   //Check if class/table has method

   if(tableHasStaticMethod(dictTable, identifierstr('find')))
       custTable = dictTable.callStatic(tableStaticMethodStr(CustTable, Find), '4000');