0

Sometimes, when I need to do more complicated stuff than change one value in datasource, I would like some method on caller. For example I have a form A with overview. Form A has method setName() (I define). I open a related detail (form B). I change something and I want to call setName on caller.

Nowdays I am doing it in following way

element.args().caller().setName();

but I am looking for more idiomatic way. So what is proper way of calling method on caller in AX 2012 R3?

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
boucekv
  • 1,220
  • 2
  • 20
  • 47

2 Answers2

3

It sounds like you need to change your development methodology if you referencing that many caller-form methods. You would mostly do that for calling doRefresh or calling updateDesign, which are both typically created methods on forms. Beyond updating the design and refeshing, you should use a class form handler.

If you must do a caller-callback, you can validate by doing:

if (formHasMethod(element.args().caller(), identifierstr(updateDesign)))
{
    element.args().caller().updateDesign();
}

You can pass your class as the caller. Here is a simple sample set of code:

\Forms\Form1\Designs\Design\[Group:Group]\Button:Button\Methods\clicked:

void clicked()
{
    FormRun     formRun;
    Args        args = new Args(formstr(Form2));
    TestClass   testLocal = new TestClass();

    testLocal.parmTestVar('ZZZ');
    args.caller(testLocal);
    formRun                    = classfactory.formRunClass(args);
    formRun.init();
    formRun.run();
    formRun.wait(true);    
}

\Forms\Form2\Methods\init:

public void init()
{
    TestClass testClass;

    super();

    testClass = element.args().caller() as testClass;
    info(strFmt("%1", testClass.parmTestVar()));
}

Look at \Forms\SalesTable and \Classes\SalesTableForm or \Classes\SysCompare\startCompareOfContextProvider and the init method

identifierStr is not depreciated. It's a normal intrinsic function, but you will get a best practice warning if you use the identifierStr function. This is because no existence checking is carried out for identifierStr. Try to use a more specific intrinsic function if one is available. See http://msdn.microsoft.com/en-us/library/aa626893.aspx

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
2

You could take a look at Calling methods on a caller form, but identifierStr is deprecated in AX 2012. As far as I know there is no way to check for form methods at compile time.

But I would suggest avoiding methods on forms. Place them in a form handler class instead, you can then use the methodStr function to check for a method.

FH-Inway
  • 4,432
  • 1
  • 20
  • 37