Monday, December 10, 2018

Add an Inventory Adjustment using .NET when the Advanced Bin / Numbered Inventory Management feature is enabled

The following sample code shows how to add an Inventory Adjustment when the "Advanced Bin/Numbered Inventory Management" is enabled. If this feature is enabled, the serial/lot number data for items must be accessed through the Inventory Detail record which is new as of the 2011.2 endpoint.

public virtual void adjustInventoryDetail()
{
 InventoryAdjustment invAdjustment = new InventoryAdjustment();

 InventoryAdjustmentInventory[] invAdjustmentItemArray = new InventoryAdjustmentInventory[1];

 RecordRef item = new RecordRef();
 item.type = RecordType.inventoryItem;
 item.typeSpecified = true;
 item.internalId = "141";

 RecordRef loc = new RecordRef();
 loc.type = RecordType.location;
 loc.typeSpecified = true;
 loc.internalId = "1";

 InventoryAssignment[] invAssignment = new InventoryAssignment[1];
 invAssignment[0] = new InventoryAssignment();
 invAssignment[0].receiptInventoryNumber = "SRINV05";

 InventoryAssignmentList invDetailList = new InventoryAssignmentList();
 invDetailList.inventoryAssignment = invAssignment;

 InventoryDetail[] invAdjustmentDetailArray = new InventoryDetail[1];
 invAdjustmentDetailArray[0] = new InventoryDetail();
 invAdjustmentDetailArray[0].inventoryAssignmentList = invDetailList;

 invAdjustmentItemArray[0] = new InventoryAdjustmentInventory();
 invAdjustmentItemArray[0].item = item;
 invAdjustmentItemArray[0].adjustQtyBy = System.Double.Parse("1");
 invAdjustmentItemArray[0].adjustQtyBySpecified = true;
 invAdjustmentItemArray[0].location = loc;
 invAdjustmentItemArray[0].inventoryDetail = invAdjustmentDetailArray[0];
 
 RecordRef account = new RecordRef();
 account.type = RecordType.account;
 account.typeSpecified = true;
 account.internalId = "64";

 InventoryAdjustmentInventoryList invList = new InventoryAdjustmentInventoryList();
 invList.inventory = invAdjustmentItemArray;
 invAdjustment.inventoryList = invList;
 invAdjustment.account = account;

 WriteResponse writeRes = _service.add(invAdjustment);

 if (writeRes.status.isSuccess)
 {
  _out.writeLn("\nAdjust Inventory successful");
 }
 else
 {
  _out.error(getStatusDetails(writeRes.status));
 }
}


 

No comments:

Post a Comment