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

Hide Enum values in Form Control


Hide Enum values in Form Control :
Well there are various situations where you  want to show only subset of Enum values :
How to do it :
Well add below , In Class declaration of form
public class FormRun extends ObjectRun
{
    SysFormEnumComboBox         sysFormEnumComboBox;
    Set                         enumSet;// = new Set(Types::Enum);
}

Add below piece of code in Form’s init method :
public void init()
{
    enumSet= new Set(Types::Enum);
    enumSet.add(Enum::A);
    enumSet.add(Enum::B);
    enumSet.add(Enum::C);
    enumSet.add(Enum::D);
   
    sysFormEnumComboBox  = sysFormEnumComboBox::newParameters(element,element.controlId(formControlStr(Form,control)),enumNum(enum),enumSet);
    super();
  
}

Well, Please have a deep look on second Argument ,which is control ID.

Friday 24 August 2012

Disable/Enable button based upon records available in List page



Disable/Enable button based upon records available in List page .
I created a new List page , and was surprised that even though there is no record available in List page ,
Edit and Edit in Grid buttons are enabled , which lead to issues:

 
So what is  solution for this :
Simple  set the”NeededRecords”  property of button to “yes”.

Tuesday 21 August 2012

Implement Catch Weight


Implement Catch Weight in New Form 


Before Starting Implementation , Let us have a Quick Look on this functionlaity 
You often use catch weight products in industries where products can vary slightly by weight or size, or both, such as the food industry. Catch weight products use two units of measure – an inventory unit and a catch weight unit. The inventory unit is the unit of measure in which the product is weighed and invoiced. The catch weight unit is the unit in which the inventory transactions are performed, such as sold, received, transferred, picked, and shipped. The nominal quantity represents the conversion between the catch weight unit and the inventory unit. Minimum and maximum quantities represent the allowed interval in which the inventory quantity can vary.

Now go for Implementation :

1 . Create a new class Extend with PdsCWFormCtrl_Std
            Override the method as required.
2. In table create two fields : Qty and PdsCWQty
3. Add display method to table :
public display PdsCWUnitId pdsCWUnitId()
{
    return PdsCatchWeight::cwUnitId(this.ItemId);
}


4.In Classdeclaration of Form   add below line :
PdsCWFormCtrl                       cwFormCtrl;
 5.In init method of Form :
        if (#PdsCatchWeightEnabled)
        {
            cwFormCtrl = yourclass::newFromForm(element);
            cwFormCtrl.initPre();
        }
       
        super();
    if (cwFormCtrl)
    {
        cwFormCtrl.parmBuffer(YourTable);
        cwFormCtrl.initPost();
    }
    6.In init method of Datasource add :

public void init()
{
    super();
    if (cwFormCtrl)
    {
        cwFormCtrl.dataSourceInitPost(YourTable);
    }
   
}
\
7.Override the Validatewrite of DS :
public boolean validateWrite()
{
    boolean ret;

    ret = super();

    if (cwFormCtrl)
    {
        ret = cwFormCtrl.dataSourceValidateWrite() && ret;
    }
   
    return ret;
}
8.Override the Active method of DS
if (cwFormCtrl)
    {
        cwFormCtrl.dataSourceActivePost();
    }

9.Override the modified of ItemId and QTY as
           
  if (cwFormCtrl)
    {
        cwFormCtrl.fieldModified(fieldnum(WO_line, ItemId));
    }