Call edit method from a main class in X++

1.6k views Asked by At

I want to recall a value of an edit method declared inside a form from a class main. How can I do it?

[Form]
public class AdvancedCustomerSchedule extends FormRun
{        
    Sorting sorting;    

    edit Sorting edtSorting(boolean set, Sorting _sorting)
    {
        if (set)
        {
            sorting = _sorting;
        }
        return sorting;
    }
 }

and the class:

class AdvancedCustomerScheduleService 
{
  static void main(Args args)
  {
       //I want to call the method edtSorting here.
  }
}

UPDATE

FormRun callerForm;
if (args.caller() is FormRun)
        {
            callerForm = args.caller() as FormRun;

            if (formHasMethod(callerForm, identifierStr(edtSorting)))
            {
                str test  = callerForm.edtSorting();
                info(test);
            }
        }
1

There are 1 answers

5
DAXaholic On BEST ANSWER

For calling methods defined on forms in general you usually use a pattern like the following:

...
FormRun callerForm;
...
if (_args.caller() is FormRun)
{
    callerForm = _args.caller();

    if (formHasMethod(callerForm, identifierStr(someMethod)))
    {
        callerForm.someMethod();
    }
    ...

Have a look at class DirPartyContactInfoFormHandler and its static main method for an example.