I am working on an add-on that was working against a 2005A version of SAP Business One and I am upgrading it to run against a 2007A Company (PL41)
I am receiving strange errors when testing the add-on.
I can add a Purchase order not based on a Goods Receipt PO without any problems but as soon as I specify a base type, entry and line I get either -1 General Error, or the Tried to Read/Write Protected Memory Error. The error I receive seems to arbitrarily change between the two.
I have read a few notes on the forums about this but none of them have proven useful in solving my problem. I have checked the DI-API version on my PC and it is definitely using 8.0.177.0 which matches the version of SBO that I am running. I have re-installed the DI etc without any success.
The following is the code snippet which I am using to test: I have verified that the referenced purchase order is open, contains the correct item, customer etc
int iResult = -1;
string sResult = string.Empty;
string sOutput = string.Empty;
try
{
sOutput += Environment.NewLine + "Connecting to company...";
sbocoy = new SAPbobsCOM.Company();
sbocoy.Server = "<insert server name here>";
sbocoy.CompanyDB = "<insert database name here>";
sbocoy.LicenseServer = "<insert server name here>:30000";
sbocoy.UseTrusted = true;
sbocoy.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2005;
sbocoy.UserName = "manager";
sbocoy.Password = "<inser sap user here>";
iResult = sbocoy.Connect();
sOutput += Environment.NewLine + "Connected";
SAPbobsCOM.Documents PO = (SAPbobsCOM.Documents)sbocoy.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders);
SAPbobsCOM.Documents GoodsReceiptPO = (SAPbobsCOM.Documents)sbocoy.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseDeliveryNotes);
sOutput += Environment.NewLine + "Get Purchase Order";
PO.GetByKey(1402);
sOutput += Environment.NewLine + String.Format("DocNum: {0}; DocEntry: {1}; ItemCode: {2}; LineNum: {3}", PO.DocNum, PO.DocEntry, PO.Lines.ItemCode, PO.Lines.LineNum);
GoodsReceiptPO.CardCode = PO.CardCode;
GoodsReceiptPO.CardName = PO.CardName;
GoodsReceiptPO.Lines.ItemCode = PO.Lines.ItemCode;
GoodsReceiptPO.Lines.ItemDescription = PO.Lines.ItemDescription;
GoodsReceiptPO.Lines.Quantity = 1.0;
GoodsReceiptPO.Lines.BaseType = int.Parse(PO.DocObjectCodeEx); // If I comment out this and the next two lines the document will add
GoodsReceiptPO.Lines.BaseEntry = PO.DocEntry;
GoodsReceiptPO.Lines.BaseLine = PO.Lines.LineNum;
sOutput += Environment.NewLine + "Adding Goods Receipt...";
iResult = GoodsReceiptPO.Add();
sResult = sbocoy.GetLastErrorDescription();
sOutput += Environment.NewLine + string.Format("Result [{0}] {1}", iResult, sResult);
}
catch (Exception ex)
{
sOutput += string.Format(Environment.NewLine + "Exception: {0}{1}SBOError: {2}", ex.Message, Environment.NewLine, sbocoy.GetLastErrorDescription());
}
The results when I try and reference the purchase order are:
Connecting to company...
Connected
Get Purchase Order
DocNum: 301396; DocEntry: 1402; ItemCode: SEANTESTITEM; LineNum: 1
Adding Goods Receipt...
Exception: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
If I comment out the 3 lines that reference the base document the Goods Receipt Adds and the following is the output...
Connecting to company...
Connected
Get Purchase Order
DocNum: 301396; DocEntry: 1402; ItemCode: SEANTESTITEM; LineNum: 1
Adding Goods Receipt...
Result [0]
The above code will work correctly if we base a Delivery Note on a Sales Order so it appears to be specifically related to the Purchasing Documents.
Edited by: Sean Archer on Feb 2, 2009 2:23 PM