cancel
Showing results for 
Search instead for 
Did you mean: 

stockTransfer.Lines.BinAllocations.SerialAndBatchNumbersBaseLine

saeid_saadat
Member
0 Kudos
623

Hi i'm trying to transfer the stock after picking them using the code below. the pick works fine but the stock transfer fails on

SerialAndBatchNumbersBaseLine at stockTransfer.Add()

------------------------------------

our requirements are as folows:

an item can be in one or many bins/batches and each bin can contain one or many batches.

we should be able to pick all or part of the released item per line.

we are using the SAP business 1 9.3 SDK

-----------------------------------

the part of code that picks the line is shown below, it receives an object containing the line details and List of Bins, each bin contains bin details and a list of Batches each batch contains the batch details and ahe quantity picked by the user.

===================== CODE ===================

PickLists_Lines oPickLists_Lines = null;
PickLists oPickLists = (PickLists)oCompany.GetBusinessObject(BoObjectTypes.oPickLists);
SAPbobsCOM.StockTransfer stockTransfer = oCompany.GetBusinessObject(BoObjectTypes.oStockTransfer);
int BatchCounter = 0;
int BinCounter = 0;
int SerialAndBatchNumbers = 0;
//int CurrentLine = oPickLine.LineNo;
oPickLists.GetByKey(oPickLine.PickListAbsEntry);// select the current line.
oPickLists_Lines = oPickLists.Lines;
oPickLists_Lines.SetCurrentLine(oPickLine.LineNo);

// -- loop through Bins.------------------
foreach (ssBin CurrentBin in oPickLine.ssBins)
{
// get the absBinNo from BinCode.
if (CurrentBin.BinAbsNo == 0 || CurrentBin.BinAbsNo == null)
{
CurrentBin.BinAbsNo = await _odbcBins.GetBinAbsEntryFromBinCode(CurrentBin.BinCode, user);
}
// get the BinToAbsNo from BinCode.
if (CurrentBin.BinToAbsNo == 0 || CurrentBin.BinToAbsNo == null)
{
// set default bin-to value to WH-DIS
if (string.IsNullOrEmpty(CurrentBin.BinToCode))
{
CurrentBin.BinToCode = "WH-DIS";
}
//get the binTo AbsNo
CurrentBin.BinToAbsNo = await _odbcBins.GetBinAbsEntryFromBinCode(CurrentBin.BinToCode, user);
}


BatchCounter = 0;// reset the batch counter

//--- now loop through Batch/s for this Bin. -----
foreach (ssBatch CurrentBatch in CurrentBin.Batches)
{
if (BatchCounter > 0)
{
oPickLists_Lines.BatchNumbers.Add();
}
oPickLists_Lines.BatchNumbers.SetCurrentLine(BatchCounter);//start from 0 and increment one per batch
oPickLists_Lines.BatchNumbers.BaseLineNumber = oPickLine.LineNo; //BaseLineNumber is Row Number (PickEntry) on PKL1 (in here oPickLine.LineNo)
oPickLists_Lines.BatchNumbers.BatchNumber = CurrentBatch.BatchNo;
oPickLists_Lines.BatchNumbers.Quantity = CurrentBatch.QtyToPick;

if (BinCounter > 0)
{
oPickLists_Lines.BinAllocations.Add();
}
oPickLists_Lines.BinAllocations.SetCurrentLine(BinCounter);//start from 0 and increment one per batch
oPickLists_Lines.BinAllocations.BaseLineNumber = oPickLine.LineNo;//BaseLineNumber is Row Number (PickEntry) on PKL1
oPickLists_Lines.BinAllocations.BinAbsEntry = CurrentBin.BinAbsNo;
oPickLists_Lines.BinAllocations.Quantity = CurrentBatch.QtyToPick;

//--- transfer stock. ------
stockTransfer.PriceList = StandardCostPriceList;
stockTransfer.JournalMemo = oPickLine.Remarks;
stockTransfer.Lines.ItemCode = oPickLine.ItemCode;
//stockTransfer.Lines.Quantity = CurrentBatch.QtyToPick;
if (BatchCounter > 0)
{
stockTransfer.Lines.BatchNumbers.Add();
}
stockTransfer.Lines.BatchNumbers.SetCurrentLine(BatchCounter);
stockTransfer.Lines.BatchNumbers.BaseLineNumber = oPickLine.LineNo; //BaseLineNumber is Row Number (PickEntry) on PKL1 (in here oPickLine.LineNo)
stockTransfer.Lines.BatchNumbers.BatchNumber = CurrentBatch.BatchNo;
stockTransfer.Lines.BatchNumbers.Quantity = CurrentBatch.QtyToPick;


_loggingUtil.Record("PickItem", $"Current pick being processed: Item: {oPickLine.ItemCode}, To: {CurrentBin.BinToCode}, From: {CurrentBin.BinCode}, " +
$"current batch:{CurrentBatch.BatchNo}", 0, "Processing", user.Username, null, user.Database, user.Connection);

//------------- read from FromBin . ------------
if (BinCounter > 0)
{
stockTransfer.Lines.BinAllocations.Add();
//SerialAndBatchNumbers = 0;
}

stockTransfer.Lines.BinAllocations.BaseLineNumber = oPickLine.LineNo;
stockTransfer.Lines.BinAllocations.BinActionType = BinActionTypeEnum.batFromWarehouse;
stockTransfer.Lines.BinAllocations.BinAbsEntry = CurrentBin.BinAbsNo;
stockTransfer.Lines.BinAllocations.Quantity = CurrentBatch.QtyToPick;
stockTransfer.Lines.BinAllocations.SerialAndBatchNumbersBaseLine = SerialAndBatchNumbers;
SerialAndBatchNumbers++;
stockTransfer.Lines.BinAllocations.SetCurrentLine(BinCounter);

//------------- Add to ToBin . ------------
stockTransfer.Lines.BinAllocations.Add();
stockTransfer.Lines.BinAllocations.BaseLineNumber = oPickLine.LineNo;
stockTransfer.Lines.BinAllocations.BinActionType = BinActionTypeEnum.batToWarehouse;
stockTransfer.Lines.BinAllocations.BinAbsEntry = CurrentBin.BinToAbsNo; //AbsEntry of WH-DIS
stockTransfer.Lines.BinAllocations.Quantity = CurrentBatch.QtyToPick;
stockTransfer.Lines.BinAllocations.SetCurrentLine(BinCounter);
stockTransfer.Lines.BinAllocations.SerialAndBatchNumbersBaseLine = SerialAndBatchNumbers;

// ******************* the line below fails with this error: *****************************

// -10: 1470000838 - Invalid \"SerialAndBatchNumbersBaseLine\"; specify a valid \"SerialAndBatchNumbersBaseLine\"

//****************************************************************

if (stockTransfer.Add() != 0)
{
var stError = $"Error with stock transfer 'stockTransfer.Add()': {oCompany.GetLastErrorCode()}: {oCompany.GetLastErrorDescription()}";
//oCompany.Disconnect();
//GarbageUtil.CleanUp(oCompany);
return stError;
}
SerialAndBatchNumbers++;

BatchCounter++;

}//for each batch.
BinCounter++;
}//for each bin.


if (oPickLists.Update() != 0)
{
var plUError = $"Error with picking item 'picklist.Update()': {oCompany.GetLastErrorCode()}: {oCompany.GetLastErrorDescription()}";
return plUError;
}

Accepted Solutions (0)

Answers (0)