Good day Everyone,
I have received the error 'Could not commit transaction: Error -1 Detected during transaction' from during 'SBOCompany.EndTransaction(SAPbobsCOM.BoWFTransOpt.wf_Commit);'. The add-on uses custom forms. The form posts 3 documents
Receipt From Production
Issue From Production
Goods Receipt
All 3 documents add without problems. If i remove the start transaction and end transaction, there is no error. all documents post properly. But if i use start transaction and end transaction, i get the message 'Could not commit transaction: Error -1 Detected during transaction'. I only got this error recently when i added warehouse and bin locations to the document codes. I am using SAP Business One 9.0 PL05. I really need the StartTransaction and EndTransaction functions. The code for the posting the documents is the below. Does anyone have any ideas on why this is happening? Am I missing something with warehouse and bin locations or is it something else?
Thanks in Advance!
public static int PostIssueForProduction(SAPbobsCOM.ProductionOrders oProductionOrder, SAPbouiCOM.DBDataSource matused_dbds, string prodDocNumber, string docDate)
{
SAPbobsCOM.Documents oIssueForProduction = null;
int output = 0;
try
{
oIssueForProduction = Global.B1Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenExit) as SAPbobsCOM.Documents;
int records = 0;
records = (matused_dbds.Size - 1);
oIssueForProduction.JournalMemo = "Issue for Production";
oIssueForProduction.Comments = "Issue for Production ";
oIssueForProduction.DocDate = SBODateToDate(docDate);
oIssueForProduction.Reference2 = prodDocNumber;
for (int i = 0; i <= records; i++)
{
string itemcode = matused_dbds.GetValue(UDFs.U_itemCode.ToString(), i).Trim();
if (string.IsNullOrEmpty(itemcode))
continue;
oIssueForProduction.Lines.SetCurrentLine(i);
oIssueForProduction.Lines.BaseType = 202;
oIssueForProduction.Lines.BaseEntry = oProductionOrder.AbsoluteEntry;
oIssueForProduction.Lines.BaseLine = i;
oIssueForProduction.Lines.Quantity = Convert.ToDouble(matused_dbds.GetValue(UDFs.U_actUsed.ToString(), i).Trim());
oIssueForProduction.Lines.WarehouseCode = Common.GetWhsCode(prodDocNumber, itemcode);
if (!string.IsNullOrEmpty(matused_dbds.GetValue(UDFs.U_binLoc.ToString(), i).Trim()))
{
oIssueForProduction.Lines.BinAllocations.BinAbsEntry = Common.GetBinEntry(matused_dbds.GetValue(UDFs.U_binLoc.ToString(), i).Trim());
oIssueForProduction.Lines.BinAllocations.Quantity = Convert.ToDouble(matused_dbds.GetValue(UDFs.U_actUsed.ToString(), i).Trim());
oIssueForProduction.Lines.BinAllocations.Add();
}
oIssueForProduction.Lines.Add();
}
output = oIssueForProduction.Add();
}
catch (Exception ex)
{
Global.B1Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
}
finally
{
//oBob = null;
GC.Collect();
}
return output;
}
public static int PostReceiptFromProduction(SAPbobsCOM.ProductionOrders oProductionOrder, double totalProducedQty, string prodDocNumber, string docDate, int binLoc)
{
SAPbobsCOM.Documents oReceiptFromProduction = null;
int output = 0;
try
{
oReceiptFromProduction = Global.B1Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry) as SAPbobsCOM.Documents;
oReceiptFromProduction.DocDate = SBODateToDate(docDate);
//for (int i = 0; i <= oProductionOrder.Lines.Count - 1; i++)
//{
oProductionOrder.Lines.SetCurrentLine(0);
oReceiptFromProduction.Reference2 = prodDocNumber;
oReceiptFromProduction.Lines.BaseType = 202; //oProductionOrders = 202
oReceiptFromProduction.Lines.BaseEntry = oProductionOrder.AbsoluteEntry;
oReceiptFromProduction.Lines.Quantity = totalProducedQty;
oReceiptFromProduction.Lines.WarehouseCode = Common.GetWhsCode(prodDocNumber);
if (binLoc != 0)
{
oReceiptFromProduction.Lines.BinAllocations.BinAbsEntry = binLoc;
oReceiptFromProduction.Lines.BinAllocations.Quantity = totalProducedQty;
oReceiptFromProduction.Lines.BinAllocations.Add();
}
oReceiptFromProduction.Lines.Add();
//}
output = oReceiptFromProduction.Add();
}
catch (Exception ex)
{
Global.B1Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
}
finally
{
//oBob = null;
GC.Collect();
}
return output;
}
public static int PostGoodsReceipt(string prodDocNumber, SAPbouiCOM.DBDataSource wasteMngtDBDS, string docDate)
{
SAPbobsCOM.Documents oGoodsReceipt = null;
int output = 0;
try
{
oGoodsReceipt = Global.B1Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry) as SAPbobsCOM.Documents;
oGoodsReceipt.Reference2 = prodDocNumber;
oGoodsReceipt.DocDate = SBODateToDate(docDate);
int records = 0;
if (wasteMngtDBDS.Offset > 0)
records = (wasteMngtDBDS.Offset - 1);
if (wasteMngtDBDS.Offset == 0)
if (string.IsNullOrEmpty(wasteMngtDBDS.GetValue(UDFs.U_itemCode.ToString(), 0).Trim()))
return 0;
for (int i = 0; i <= records; i++)
{
oGoodsReceipt.Lines.ItemCode = wasteMngtDBDS.GetValue(UDFs.U_itemCode.ToString(), i).Trim();
if (string.IsNullOrEmpty(oGoodsReceipt.Lines.ItemCode))
continue;
oGoodsReceipt.Lines.Quantity = Convert.ToDouble(wasteMngtDBDS.GetValue(UDFs.U_quantity.ToString(), i));
if (oGoodsReceipt.Lines.Quantity <= 0)
continue;
oGoodsReceipt.Lines.WarehouseCode = Common.GetWhsCode(Common.GetBinEntry(wasteMngtDBDS.GetValue(UDFs.U_binLoc.ToString(), i).Trim()));
oGoodsReceipt.Lines.BinAllocations.BinAbsEntry = Common.GetBinEntry(wasteMngtDBDS.GetValue(UDFs.U_binLoc.ToString(), i).Trim());
oGoodsReceipt.Lines.BinAllocations.Quantity = Convert.ToDouble(wasteMngtDBDS.GetValue(UDFs.U_quantity.ToString(), i));
oGoodsReceipt.Lines.BinAllocations.Add();
oGoodsReceipt.Lines.Add();
}
output = oGoodsReceipt.Add();
}
catch (Exception ex)
{
output = -1;
ErrorManager.WriteToLog(ex);
Global.B1Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
}
finally
{
GC.Collect();
}
return output;
}