Dynamics 365 Finance can't close current form x++

635 Views Asked by At

In the init method of an intermediate form I'm trying to open a new form and close current one. Below code opens the second form however with an error message "cannot call close without detach or wait" although I tried adding element.detach() but error persists

void Init()       
   {

    FormRun formRun;
    Args args = new Args();
          
    super();   
            
    element.close();//can't close  

    args.name(formstr(Form1));
    formRun = ClassFactory.formRunClass(args);

    formRun.init();
    formRun.run();
    formRun.detach();
}
1

There are 1 best solutions below

0
piku On

On the intermediate form overridden the run() method and after super wrote

element.detach();
element.close(); 

and therefore it worked.