AX / D365FO – How to call an Action Menu Item in a Form event handler

In this example I want to call a menu item every time a Data source record is deleted

[FormDataSourceEventHandler(formDataSourceStr(ProjSalesItemReq, SalesLine), FormDataSourceEventType::Deleted)]
public static void SalesLine_OnDeleted(FormDataSource sender, FormDataSourceEventArgs e)
        Args args = new Args();
        FormRun formRun = sender.formRun(); //Get FormRun
        FormDataSource  salesLine_ds = formRun.dataSource(formDataSourceStr(SalesLine, SalesLine)) as FormDataSource; //Get DataSource
        SalesLine       salesLine    = salesLine_ds.cursor(); //Get DataSource record
        args.caller(formRun); //Pass formRun to Args Parameters
        args.record(salesLine); //Pass DataSource record to Args Parameters

        new MenuFunction(menuitemactionstr(Al0CalculateInarcassaCharges), MenuItemType::Action).run(Args); //This code calls an action menu item called Al0CalculateInarcassaCharges
        salesLine_ds.refresh(); //Refresh the Form grid
        salesLine_ds.research(true); //Refresh the Form grid

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s