Calling instance methods through reflection
Hi-
Following job can execute instance method in a class. I had a scenario where I wanted to test my upgrade scripts and you know for running upgrade script there is a need to run the process that consumes a large amount of time, so I thought following job would be useful for the developers
static void callMethodJob(Args _args)
{
DictClass dictClass = new DictClass(classNum(ReleaseUpdateDB60_Cust));
Object classObj = dictClass.makeObject();
DictMethod dictMethod;
int i;
for (i=1; i < dictClass.objectMethodCnt(); i++)
{
if (Global::strStartsWith(dictClass.objectMethod(i), “update”))
{
dictClass.callObject(dictClass.objectMethod(i), classObj);
}
info(strFmt(“%1, %2, %3″, dictClass.objectMethodCnt(), dictClass.objectMethod(i), dictClass.name()));
}
}
Posted on February 23, 2012, in Dynamics Ax Troubleshooting. Bookmark the permalink. 3 Comments.


Hi Faddy,
thank you for the info. I just want to mention that with the
“for (i=1; i < dictClass.objectMethodCnt(); i++)" statement you are missing the last method of the class, as the counter is not zero based.
We cannot start with 0 since Arrays or collections in x++ do not start with 0. following should be the code to get all the methods
for (i=1; i < dictClass.objectMethodCnt() +1; i++)
Or may be this
for (i=1; i <= dictClass.objectMethodCnt(); i++)