Monday 27 August 2012

Inventory Dimension enable /disable based upon item selected


Inventory Dimension enable /disable based upon item selected

Hi Friends, Well we have seen a no of times we face the issue to have  the correct Inventory dimension field enabled/disabled based upon Item selected . How to achieve this :
1.       Add below declaration in your class declaration of form

         public class FormRun extends ObjectRun
        {
          InventDimCtrl_Frm       inventDimFormSetup;
        }
2.       Add below piece in form’s Init method :
public void init()
{
    element.updateDesign(InventDimFormDesignUpdate::Init);
}


3.       Add below method :
InventDimCtrl_Frm inventDimSetupObject()
{
    return inventDimFormSetup;
}

4.   Add below method :
void updateDesign(InventDimFormDesignUpdate mode)
{
    inventDimParm   inventDimParmVisible;
    inventDimParm   inventDimParmEnabled;

    switch (mode)
    {
        case InventDimFormDesignUpdate::Init          :
        case InventDimFormDesignUpdate::LinkActive    :
            if (!inventDimFormSetup)
            {
                inventDimFormSetup  = InventDimCtrl::newFromForm(element);
            }
            inventDimFormSetup.parmSkipOnHandLookUp(true);

            if (element.args().dataset() == tableNum(datasource))
            {
                inventDimParmVisible = EcoResProductDimGroupSetup::newItemId(Item_Adjustment.ItemId).inventDimParmActiveDimensions();
            }
            else
            {
                inventDimParmVisible.initProductDimensionsAllGroups();
            }
            inventDimFormSetup.parmDimParmVisibleGrid(inventDimParmVisible);
            break;

        case InventDimFormDesignUpdate::Active        :
            inventDimFormSetup.formActiveSetup();
            inventDimParmEnabled = EcoResProductDimGroupSetup::newItemId(datasource.ItemId).inventDimParmActiveDimensions();
            inventDimParmEnabled.InventLocationIdFlag = true;
            inventDimFormSetup.parmDimParmEnabled(inventDimParmEnabled);
            inventDimFormSetup.formSetControls(true);
            //inventDimFormSetup.

            break;

        case InventDimFormDesignUpdate::FieldChange   :
            inventDimFormSetup.formActiveSetup();
            inventDimParmEnabled = EcoResProductDimGroupSetup::newItemId(datasource.ItemId).inventDimParmActiveDimensions();
            inventDimFormSetup.parmDimParmEnabled(inventDimParmEnabled);
            //inventDimFormSetup.
            inventDimFormSetup.formSetControls(true);
            break;

        default :
            throw error(strfmt("@SYS54195",funcname()));
    }
}


5.       Add below lines in Active method of DS :
public int active()
{
    int ret;
    ret = super();
    element.updateDesign(InventDimFormDesignUpdate::Active);
   
    return ret;
}

6      Add below line in ItemId’s modified method :
element.updateDesign(InventDimFormDesignUpdate::FieldChange);


Well you are ready to go :
 PS : You want to enable\ disable one particular  Dimension field irrespective  of Item selected , how to do : 
Simple put the corresponding flag true or false as
inventDimParmEnabled.InventLocationIdFlag = true;


Hope this will help you guys   J

5 comments:

  1. Hi Gaurav,

    Can you please share the code for how to make the inventory dimension fields mandatory based on product dimension. This code works well for enable/disable but i am looking for making invent dim fields mandatory too...

    ReplyDelete
    Replies
    1. you can add the beloe code in DS :
      public boolean validateWrite()
      {
      boolean ret;


      ret = super();
      ret = ret && InventTable::checkProductDimensions(yourtable.ItemId,InventDim);
      return ret;
      }

      Delete
    2. Thanks for the code, it is helpful. Do we have any validation for Tracking dimensions like product dimensions?

      Delete
    3. Sorry not tracking, i am looking for storage dimension.

      Delete
  2. Hello.
    This code does not work with Storage Dimensions, does it?

    ReplyDelete