Skip to Content
0
Former Member
Feb 02, 2016 at 06:54 PM

StockTransfer error on 9.1

43 Views

Hello all,

I updated B1 9.0 to 9.1 and now I'm getting an error trying to do a stock transfer throught DI API. On 9.0 it was working perfectly.It seems there's something wrong in the BinAllocation object. When I try to access it, my application crashes. I'm getting the error at "if (stockTransfer.Lines.BinAllocations.BinAbsEntry != 0)"

StockTransfer stockTransfer = (StockTransfer)SBOApp.Company.GetBusinessObject(BoObjectTypes.oStockTransfer)


stockTransfer.DocDate = DateTime.Now;
stockTransfer.TaxDate = DateTime.Now;
stockTransfer.FromWarehouse = labelList[0].WarehouseFrom;
stockTransfer.ToWarehouse = warehouse;
stockTransfer.Comments = comments;
               
foreach (LabelTransferModel label in labelList)
{
  if (!String.IsNullOrEmpty(stockTransfer.Lines.ItemCode))
  {
  stockTransfer.Lines.Add();
  }


  stockTransfer.Lines.ItemCode = label.ItemCode;
  stockTransfer.Lines.WarehouseCode = warehouse;
  stockTransfer.Lines.Quantity = label.Quantity;


  if (SZS.Common.Controllers.ItemController.GetItemManagement(label.ItemCode) == SZS.Common.Enums.ItemManagTypeEnum.Batch)
  {
  stockTransfer.Lines.BatchNumbers.BatchNumber = label.Batch;
  stockTransfer.Lines.BatchNumbers.Quantity = label.Quantity;
  }


  if (stockTransfer.Lines.BinAllocations.BinAbsEntry != 0)
  {
  stockTransfer.Lines.BinAllocations.Add();
  }


  if (label.LocIdFrom == 0)
  {
  label.LocIdFrom = LocaleController.GetLocaleId(label.LocFromDesc);
  }


  stockTransfer.Lines.BinAllocations.BinActionType = BinActionTypeEnum.batFromWarehouse;
  stockTransfer.Lines.BinAllocations.BinAbsEntry = label.LocIdFrom;
  stockTransfer.Lines.BinAllocations.Quantity = label.Quantity;
  stockTransfer.Lines.BinAllocations.SerialAndBatchNumbersBaseLine = 0;


  stockTransfer.Lines.BinAllocations.Add();


  stockTransfer.Lines.BinAllocations.BinActionType = BinActionTypeEnum.batToWarehouse;


  if (label.LocIdFrom == 0)
  {
  label.LocTo = LocaleController.GetLocaleId(label.LocToDesc);
  }
  stockTransfer.Lines.BinAllocations.BinAbsEntry = label.LocTo;
  stockTransfer.Lines.BinAllocations.Quantity = label.Quantity;
  stockTransfer.Lines.BinAllocations.SerialAndBatchNumbersBaseLine = 0;
}


if (stockTransfer.Add() != 0)
{
  error = "Erro ao efetuar transferência: " + SBOApp.Company.GetLastErrorDescription();
}


if (String.IsNullOrEmpty(error))
{
  // Se não der nenhum erro, dá um commit na transação
  SBOApp.Company.EndTransaction(BoWfTransOpt.wf_Commit);
}
else
{
  // Se não, volta tudo
  if (SBOApp.Company.InTransaction)
  {
  SBOApp.Company.EndTransaction(BoWfTransOpt.wf_RollBack);
  }
}


GC.WaitForPendingFinalizers();


Marshal.ReleaseComObject(stockTransfer);
stockTransfer = null;

GC.Collect();

Please help!

Thanks