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;
    }

How to create InventTransfer Order using X++

static void TransferOrdersImport(Args _args)

#define.WarehouseFrom("AHK")
#define.WarehouseTo("SIMON")
#define.ShipDate("1/1/2019")
#define.ReceiveDate("1/1/2019)
#define.ItemId("ICTest")
#define.Qty(1)
#define.Site("HK")
#define.Warehouse("AHK")
InventTransferTable inventTransferTable;
InventTransferLine inventTransferLine;
InventDim inventDim;

try

ttsbegin;
//Order header inventTransferTable.clear();
inventTransferTable.initValue();
inventTransferTable.TransferId = InventTransferTable::numberSeq().num();
inventTransferTable.InventLocationIdFrom = #WarehouseFrom;
inventTransferTable.InventLocationIdTo = #WarehouseTo;
  inventTransferTable.DlvModeId = CustVendTransportPointLine::defaultDeliveryMode(inventTransferTable.InventLocationIdFrom,'','','','',inventTransferTable.InventLocationIdTo);
inventTransferTable.InventLocationIdTransit = InventLocation::find(inventTransferTable.InventLocationIdFrom).InventLocationIdTransit;

inventTransferTable.initFromAddress();
inventTransferTable.initToAddress();
inventTransferTable.ShipDate = str2Date(#ShipDate, 213);

inventTransferTable.ReceiveDate = str2Date(#ReceiveDate, 213);

if (inventTransferTable.validateWrite())
{
inventTransferTable.insert();
//Order line inventDim.clear();
  inventDim.InventSiteId = "HK";
inventDim.InventLocationId = "AHK";
inventTransferLine.clear();
inventTransferLine.initValue();
inventTransferLine.ItemId = #ItemId;
inventTransferLine.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;

inventTransferLine.QtyTransfer = #Qty;

inventTransferLine.initFromInventTableModule(InventTableModule::find(inventTransferLine.ItemId,ModuleInventPurchSales::Invent));
inventTransferLine.QtyRemainReceive = inventTransferLine.QtyTransfer;
inventTransferLine.QtyRemainShip = inventTransferLine.QtyTransfer; 
inventTransferLine.ShipDate = str2Date(#ShipDate, 213);
inventTransferLine.ReceiveDate = str2Date(#ReceiveDate, 213);
inventTransferLine.initFromInventTransferTable(inventTransferTable, false);
inventTransferLine.LineNum = InventTransferLine::lastLineNum(inventTransferLine.TransferId) + 1.0;
if (inventTransferLine.validateWrite())
{
inventTransferLine.insert();
}
  else
throw error("Error in Order line");
}
  else
throw error("Error in Order header");
ttscommit;
}
  catch {
  error("Error!");
return;
}
  info("Done!");
}

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

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