D365: How to get caller form name in Form extension class

Purpose:

Demonstrate how to get caller form name in a Form extension class in X++.

Application:

Dynamics 365 for Finance and Operations

Solution:

The code below gives a very good example of how can get the caller form name in a Form extension class in X++ which then can be used to run the business logic.

In the code below, we’re adding a display method for a control on the form RetailAddItems to display Site. We’re getting Site from a form data source on the caller form. In this case, caller form is PurchTable and caller form data source is also PurchTable.

Code

[ExtensionOf(formStr(RetailAddItems))]
internal final class MAK_RetailAddItems_Extension
{
	display InventSiteId displayPurchSiteId()
    {
        InventSiteId siteId;
        FormRun callerFormRun;

        callerFormRun = this.args().caller();

        if (callerFormRun.name() == formStr(PurchTable))
        {
            FormDataSource purchTable_ds = callerFormRun.dataSource(formDataSourceStr(PurchTable, PurchTable)) as FormDataSource;
            PurchTable purchTable = purchTable_ds.cursor() as PurchTable;

            if (purchTable)
            {
                siteId = purchTable.InventSiteId;
            }
        }

        return siteId;
	}
}

Leave a comment

Blog at WordPress.com.

Up ↑