D365/AX7:Call any method of caller form in a class or any other form or Extension etc.

Call any method of caller form into a class or any other form

Requirement

Here is very impressive piece of code for calling any method of custom or base form in a class or any form.

In standard form “PurchCreateFromSalesOrder” there is a base method specifyVendAccount which i need to call on extension class of form “PurchCreateFromSalesOrder” on the modification of a new custom control i have created separately on the same form “PurchCreateFromSalesOrder“.

Sample Code With Explanation

I created one class and a new event method.

[FormControlEventHandler(formControlStr(PurchCreateFromSalesOrder, FormStringControl1), FormControlEventType::Modified)]
public static void FormStringControl1_OnModified(FormControl sender, FormControlEventArgs e)
{
FormRun formRun =sender.formRun();
SalesLine salesLine;
FormDataSource formDataSource;
Object formRunObject;
;
salesLine = SalesLine::findRecId(68719716393);
formRunObject = formRun.dataSource(1);
formRunObject.specifyVendAccount(true, SalesLine, ‘INMF-000001’); //here i am calling the method of  form datasource 🙂
formRun.dataSource(1).write();
formRun.dataSource(1).research(true);
formRun.dataSource(1).refresh();
}

Cheers 🙂

Piyush Adhikari

Leave a Reply