D365FOE. Form personalization for developers.

Blog_image_dashboard.jpg

Often in AX one form could be used for different business entities, like customer and vendor external items. And because they use same CustVendExternalItem form under the hood personalization of it affects all entities in the same time. But what if user wants to add new control via personalization only for customer’s and does not want to see it for vendor’s external items?  Now it is possible with a small customization.

In D365 new FormRunConfigurationClass class has been introduced to control form personalization. It saves and restores all changes done by user: new controls added via personalization, columns resize, columns hide, etc. Each form has new property – configurationOwner() that is used by FormRunConfigurationClass to resolve configuration. By default, it is equal to a form name.

To split customer external items and vendor external items form personalization all we need to do is to set configurationOwner()  to overAllModule in the init() method of CustVendExternalItem  form, that is equal to ModuleInventCustVend::Cust for customer and to ModuleInventCustVend::Vend for vendor:

[ExtensionOf(formStr(CustVendExternalItem))]
public final class CustVendExternalItemForm_Extension
{
    public void init()
    {
        //copy-pasted this code from init method because it resolves module after super() and we need it before
        switch (this.args().parmEnum())
        {
            case ModuleInventPurchSalesVendCustGroup::Purch,
                 ModuleInventPurchSalesVendCustGroup::Vend,
                 ModuleInventPurchSalesVendCustGroup::VendGroup:
                 // set personalization owner
                 this.setConfigurationOwner(enum2str(ModuleInventCustVend::Vend));
                break;

            case ModuleInventPurchSalesVendCustGroup::Sales,
                 ModuleInventPurchSalesVendCustGroup::Cust,
                 ModuleInventPurchSalesVendCustGroup::CustGroup :
                 // set personalization owner
                 this.setConfigurationOwner(enum2str(ModuleInventCustVend::Cust));
                break;
        }

        next init();
    }
}

This property should be set before super() of init() method of the form, so if you have controls added in the run-time it won’t affect them. However, FormRunConfigurationClass can load saved personalization for this control as well. Let’s expand our example with new run-time control and load personalization for it:

[ExtensionOf(formStr(CustVendExternalItem))]
public final class CustVendExternalItemForm_Extension
{
    public void init()
    {
        //copy-pasted this code from init method because it resolves module after super() and we need it before
        switch (this.args().parmEnum())
        {
            case ModuleInventPurchSalesVendCustGroup::Purch,
                ModuleInventPurchSalesVendCustGroup::Vend,
                 ModuleInventPurchSalesVendCustGroup::VendGroup:
                this.setConfigurationOwner(enum2str(ModuleInventCustVend::Vend));
                break;

            case ModuleInventPurchSalesVendCustGroup::Sales,
                ModuleInventPurchSalesVendCustGroup::Cust,
                 ModuleInventPurchSalesVendCustGroup::CustGroup :
                this.setConfigurationOwner(enum2str(ModuleInventCustVend::Cust));
                break;
        }

        next init();

        //add runtime control
        FormGridControl gridControl = this.design().controlName(formControlStr(CustVendExternalItem, Grid));
        FormStringControl newControl = gridControl.addControl(FormControlType::String, 'NewControl');
        newControl.label('New control');

        //load personalization for runtime control
 this.configurationHelper().getLoadedConfigurationProfile().applyRuntimePropertiesForControl(this, gridControl, newControl);
    }
}

That’s only two examples of FormRunConfigurationClass usage, but I’m sure that my curious reader will find more.

Advertisements