Monday, February 17, 2020

How to enable the dimension fields based on the Item selected on the form.

[Form]
public class KMTShipFromWarehouses extends FormRun
{
    InventDimCtrl_Frm_EditDimensions        inventDimFormSetup;

    /// <summary>
    /// InventDimFormDesignUpdate
    /// </summary>
    /// <returns></returns>
    public InventDimCtrl_Frm_EditDimensions inventDimSetupObject()
    {
        return inventDimFormSetup;
    }

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

    /// <summary>
    /// To Display product dimensions
    /// </summary>
    /// <param name = "mode">InventDimFormDesignUpdate</param>
    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.InventSizeIdFlag       = true;
                    inventdimparmvisible.InventColorIdFlag      = true;
                    inventdimparmvisible.InventSiteIdFlag       = true;
                    inventdimparmvisible.InventLocationIdFlag   = true;
                    inventDimFormSetup.parmDimParmVisibleGrid(inventDimParmVisible);
                }
            // Datasource Active
            case InventDimFormDesignUpdate::Active  :
                inventDimFormSetup.formActiveSetup(InventDimGroupSetup::newItemId(KMTShipFromWarehouses.ItemId)); //InventDimDisplay is the datasource name.
                inventDimFormSetup.formSetControls( true);
                break;

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

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

    [DataSource]
    class KMTShipFromWarehouses
    {
         /// <summary>
        /// To Display product dimensions
        /// </summary>
        public int active()
        {
            int ret;
            ret = super();
            element.updateDesign(InventDimFormDesignUpdate::Active);
           
            //If record is saved then allow edit for dimension field is false.
            if (KMTShipFromWarehouses_ds.cursor())
            {
                this.formRun().design(0).controlName('InventoryDimensionsGrid_InventSizeId').allowEdit(false);
                this.formRun().design(0).controlName('InventoryDimensionsGrid_InventColorId').allowEdit(false);
            }
            return ret;
        }

        [DataField]
        class ItemId
        {
            /// <summary>
            /// To Display product dimensions
            /// </summary>
            public void modified()
            {
                super();
   
                element.updateDesign(InventDimFormDesignUpdate::FieldChange);
                InventDim.clearNotSelectedDim(element.inventDimSetupObject().parmDimParmEnabled());
            }

        }

    }

    [DataSource]
    class InventDim
    {
        [DataField]
        class InventSizeId
        {
            /// <summary>
            /// To display site and warehouse
            /// </summary>
            public void modified()
            {
                InventTable                 inventTable = inventTable::find(KMTShipFromWarehouses.ItemId);

                InventItemOrderSetupType    setupType   = InventItemOrderSetupType::Invent;
               
                super();

                inventDim.InventSiteId      = inventTable.inventItemOrderSetupMap(setupType).inventSiteId(inventDim.InventSiteId, inventTable);

                inventDim.InventLocationId  = inventTable.inventItemOrderSetupMap(setupType,InventDim::findOrCreate(inventDim).InventDimId).inventLocationId(inventDim.InventLocationId,inventTable,inventDim.InventSiteId);
               
            }

        }

    }

}


Validate Write method on table

/// <summary>
    /// Validate the required fields
    /// </summary>
    /// <returns>Boolean</returns>
     public boolean validateWrite()
    {
        boolean ret = true;
       
        str errorMessage;

        InventTable     inventTable;
        InventDimParm   inventDimParm;
       
        inventTable   = InventTable::find(this.ItemId);
        inventDimParm =  InventDimParm::activeDimFlag(InventDimGroupSetup::newInventTable(inventTable));

        InventDim kmtInventDim = InventDim::find(this.InventDimId);

        if(inventDimParm.InventSizeIdFlag && !kmtInventDim.InventSizeId)
        {
            errorMessage = strFmt("@SYS26332", Fieldid2PName(tableNum(InventDim),fieldNum(InventDim, InventSizeId)));
        }

        if(inventDimParm.InventColorIdFlag && !kmtInventDim.InventColorId)
        {
            errorMessage = errorMessage + " " + strFmt("@SYS26332", Fieldid2PName(tableNum(InventDim),fieldNum(InventDim, InventColorId)));
        }

        if(kmtInventDim.InventSiteId && !kmtInventDim.InventLocationId)
        {
            errorMessage = errorMessage + " " + strFmt("@SYS26332", Fieldid2PName(tableNum(InventDim),fieldNum(InventDim, InventLocationId)));
        }

        if(errorMessage)
        {
            ret = checkFailed(errorMessage);
        }

        else
        {
            ret = super();
        }

        return ret;
    }

3 comments:

How to enable the dimension fields based on the Item selected on the form.

[Form] public class KMTShipFromWarehouses extends FormRun {     InventDimCtrl_Frm_EditDimensions        inventDimFormSetup;     /// ...