Monday, February 17, 2020

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!");
}

2 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;     /// ...