Skip to main content
Post a question

Notifications

Community site session details

Community site session details

Session Id : XPycjC9/rtVNGN7HS9lYAx
Dynamics 365 Community / Blogs / DAX Beginners / How to: Dynamically display...

How to: Dynamically display inventory dimension

Christian Silva Profile Picture Christian Silva 707

Good day everyone,

Today I will post about how to display only the inventory dimensions selected by the user.
This post is rather long because I decided show it step-by-step but I hope you guys enjoy it.

1. The table must have the field InventDimId and it must have a relation with InventDim.

Image

2. Create a new Form. My form has two data sources, InventDimDisplay and InventDim (required) and a grid.

Image

3. Set the InventDim data source properties to:

Image

4. On form Design, create a new Grid and move the ItemId to your grid and then create a new Group and then set the properties below:

Image

5. On class declaration add the following piece of code:

public class FormRun extends ObjectRun
{
    // Declare the class InventDimCtrl_Frm_EditDimensions
    InventDimCtrl_Frm_EditDimensions        inventDimFormSetup;
}

6. Now, create a new method in form.

public InventDimCtrl_Frm_EditDimensions inventDimSetupObject()
{
    return inventDimFormSetup;
}

7. Override the form’s method Init.

public void init()
{
    super();
    // This method will be used to show default fields at form startup
    element.updateDesign(InventDimFormDesignUpdate::Init);
}

8. Create a new method, this method is responsible to show the Inventory Controls.

void updateDesign(InventDimFormDesignUpdate mode)
{
    InventDimParm inventDimParmVisible;

    switch (mode)
    {
        // Form Init
        case InventDimFormDesignUpdate::Init    :
            if (!inventDimFormSetup)
                inventDimFormSetup  = InventDimCtrl_Frm_EditDimensions::newFromForm(element);
                inventDimFormSetup.parmSkipOnHandLookUp( true);

                // Use the methods on InventDimParm
                // to set which dimensions to show when form is initialized
                inventdimparmvisible.inventsiteidflag       = true;
                inventdimparmvisible.InventLocationIdFlag   = true;
                inventDimFormSetup.parmDimParmVisibleGrid(inventDimParmVisible);

        // Datasource Active
        case InventDimFormDesignUpdate::Active  :
            inventDimFormSetup.formActiveSetup(InventDimGroupSetup::newItemId(InventDimDisplay.ItemId)); //InventDimDisplay is the datasource name.
            inventDimFormSetup.formSetControls( true);
            break;

        // Datasource Field change
        case InventDimFormDesignUpdate::FieldChange :
            inventDimFormSetup.formActiveSetup(InventDimGroupSetup::newItemId(InventDimDisplay.ItemId)); //InventDimDisplay is the datasource name.
            InventDim.clearNotSelectedDim(inventDimFormSetup.parmDimParmEnabled()); // InventDim is referring to datasource name
            inventDimFormSetup.formSetControls( true);
            break;

        default :
            throw error(strFmt ("@SYS54195", funcName()));
    }
}

9. We have to create a method on data source to update our table InventDimId and use the method Active to refresh the controls.
Override Data source’s method Active.

public int active()
{
    int ret;
    ret = super();
    element.updateDesign(InventDimFormDesignUpdate::Active);
    return ret;
}

10. Now, override the method Modified for ItemId field in your data source.

public void modified()
{
    super();
   
    element.updateDesign(InventDimFormDesignUpdate::FieldChange);
    InventDim.clearNotSelectedDim(element.inventDimSetupObject().parmDimParmEnabled());
}

11. We have to create a MenuItemButton to call the Display Dimension form where the user can select which dimensions he want to display.
Set the following properties:

MenuItemType: Display
MenuItemName: InventDimParmFixed

12. By the end of this tutorial, your form should look like this.

Image

13. The results:

Image



This was originally posted here.

Comments

*This post is locked for comments