Saturday, February 6, 2021

Caller Form Name, Record from Called Form In D365FO

 Hi guys, Today we see how to get Caller Form Name, Record from Called Form In D365FO.


  • Caller form name:

        FormRun caller,formRun = sender.formRun();//FormControl(sender) childform     Args args = new Args();     ;     caller = sender.formRun().args().caller();     if(caller.args().name() == formStr(TestForm)

  • Caller data source name:

        element.args().dataset() == tableNum(CustTable)

  • Caller form menu item name:

            FormRun caller = sender.args().caller(); // xFormRun(sender) child form formrun

        caller.args().menuItemName() == menuItemDisplayStr(PIDInventSite))  

  • Get menu item name:

        element.args().menuItemName();

  • Get current record of caller form:
    • Way1 : 
                if (element.args().dataset() == tableNum(CustTable))
     {     CustTable custTable = element.args().record();
         }
    • Way2 : (Get Any data source current record)
               FormDataSource formDataSource;
FormRun caller; //caller form caller = element.args().caller(); if (caller.args().name() == formStr(MyForm)) { for (i = 0; i <= caller.dataSourceCount(); i++) { formDataSource = caller.dataSource(i); if (formDataSource && formDataSource.table() == tableNum(MyTable)) { MyTable myTableLoc = formDataSource.cursor(); break; } } }

Example:

Calling From Parent:

[FormControlEventHandler(formControlStr(TestForm, Test), FormControlEventType::Clicked)]
public static void Test_OnClicked(FormControl sender, FormControlEventArgs e)
{
    TableA            tableA= sender.formRun().dataSource().cursor() as TableA ;
    Args              args = new Args();
    FormRun          formRun;
    ;

    args.name(formStr(TestChild));
    args.record(tableA);
    args.caller(sender.formRun());

    formRun = classfactory.formRunClass(args);

    formRun.init();
    formRun.run();
    formRun.wait();
}

In child:


Form Init:

public void init() { super(); if (element.args().dataset() == tableNum(CustTable)) { CustTable custTable = element.args().record(); MyTable_ds.query().dataSourceTable(tableNum(MyTable)).addRange(fieldNum(MyTable,
                                                FieldName)).value(custTable.AccountNum); }
  

 
Ok button:

[FormControlEventHandler(formControlStr(TestChild, Ok), FormControlEventType::Clicked)] public static void Ok_OnClicked(FormControl sender, FormControlEventArgs e) { TableA tableA; FormRun caller,formRun = sender.formRun(); Args args = new Args(); ; caller = sender.formRun().args().caller(); if(caller.args().name() == formStr(TestForm)) { tableA= sender.formRun().args().record() as TableA ; info(strfmt('%1',tableA.Id)); } }

Keep Daxing!!

No comments:

Post a Comment