0

First off, the code displayed below, extracted from where it is sitting in our AX, WORKS. Both the class creating the dialog and the class containing the lookup are set to run on "Called From". The class where the dialog method sits is an abstract class. Could that cause this error? The parent class also does not extend RunBase. Not sure if that makes a difference or not.

I am receiving this error, "The method DialogControl.control cannot be called from the server; use methods on the DialogField class instead", when attempting to add a lookup override to a dialog field.

Any help or workarounds would be greatly appreciated.

protected boolean dialog()
{
    Dialog  dialog = new Dialog("My Dialog", this);
    DialogField myField;
    boolean ok;

    myField = dialog.addFieldValue(extendedTypeStr(MyStringType),
        "DefaultValue", "FieldCaption", "FieldHelp");
    myField.registerOverrideMethod(
        methodStr(FormStringControl, lookup),
        methodStr(MyClassName, MyLookupMethod),
        new MyClassName());
    ok = dialog.run();
}

private void MyLookupMethod(FormStringControl _control)
{
    SysTableLookup          sysTableLookup;
    QueryBuildDataSource    queryBuildDataSource;
    Query                   query = new Query();

    queryBuildDataSource = query.addDataSource(tablenum(CustTable));

    sysTableLookup = SysTableLookup::newParameters(tablenum(CustTable), _control);
    sysTableLookup.addLookupfield(fieldnum(CustTable, AccountNum),  true);
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
Brad
  • 1,357
  • 5
  • 33
  • 65
  • For testing purposes, it should be easy to temporarily remove the `abstract` keyword from the class building the dialog. Does your implementation use the `SysOperation` framework? Have you tried making `MyLookupMethod` public? I don't think you can register a private or protected method from another class as override method. Also, is this AX 2012 or another version? Also also, take a look at https://stackoverflow.com/questions/24791355/dynamics-ax-2012-custom-lookup-in-a-dialog – FH-Inway Jun 22 '20 at 18:34
  • Thanks for the quick reply. Same issue with abstract removed. Changing the lookup method from private to public didn't seem to make a difference (the private method does work when I make a separate test class). The current class doesn't extend RunBase or use SysOperation. And this is AX 2012. I ran through that other article before posting, but will give it another look. Thanks again. – Brad Jun 22 '20 at 19:59
  • Since your separate test class works, it seems to be caused by something in the abstract class. Next step would be to remove step by step parts of the abstract class until it looks like the separate test class. One of the removed parts should resolve the issue. Or you go the other way and start adding stuff to the separate test class until it looks like the abstract class. – FH-Inway Jun 22 '20 at 20:56
  • You are right. Dreading that, because this dialog is actually buried in an ISV's class that is being called who knows how many levels deep in their code. : ) – Brad Jun 23 '20 at 11:49

1 Answers1

0

Ok, I finally found this. Thought I'd post the answer to help others.

While the class is set to Called From, as is the action menu item that calls it, it was re-instantiating itself using a construct method. The static Construct method was set as a server method.

Brad
  • 1,357
  • 5
  • 33
  • 65