2
votes

I have 3 classes each with a method which run some calculation and write the values in different fields, this method also writes the classname into a field from where the method runs from.

This works fine.

I recently created a button to re-run the method, from the class the method originally run from.

For example:

Class1 RunMethod
Class2 RunMethod
Class3 RunMethod

I am now creating the method for the action button when clicked, but I have no clue how to run a specific method from the class where it originally ran from. The class name is in a field.

I think I can accomplish this with SysDictClass, but I have no clue how to start, how can I best start with this method?

1

1 Answers

5
votes

This should get you the idea. I wrote it in AX 2009 but it should probably work in AX 2012 as well.

public static client void SysDictClassJob()
{
    ClassId      classId;
    Object       obj;
    SysDictClass sysDictClass;
    ;

    // Create instance (if you are going to call a member method)
    classId = className2Id('SomeClass');
    obj = classFactory.createClass(classId);

    // Invoke member method
    sysDictClass = new SysDictClass(classId);
    sysDictClass.callObject('yourMemberMethod', obj);

    // Invoke static method
    sysDictClass.callStatic('yourStaticMethod');
}