Friday, January 10, 2020

D365 Capture switch between gridview and details view

Microsoft Dynamics 365 for Operations & Financials

In a form with the Details Master pattern, the user switches between viewing the list view (grid with all records) and a details view (only one record). This navigation happens within the same form, so there is no form initialization upon entering a record detail or going back to the list.

If you want to something to happen when the user switches between views, you need to capture the switch itself.

Let's say you want to enable a button in list view, but disable it in detail view.
Override the task() method like this:
public int task(int _p1) { int ret; #Task if(_p1 == #taskSwitchToDetailsView) { MyButton.enabled(false); } else if(_p1 == #taskSwitchToGridView) { MyButton.enabled(true); } ret = super(_p1); return ret; }
You might also want to enable or disable the button when the form opens.
Since controls are rendered after the init() is called, you need to put the code in the run() method.
You need to check if the form is in list or detail view mode:
public void run() { super(); if(element.viewOptionHelper().getViewOption() == FormViewOption::Details) { MyButton.enabled(false); } }