on 09-22-2008 2:40 AM
Hi,
I am trying to create DIAPI code to add an order to the system, and I keep running into an error,
which is error code 1, and error string 'Unable to commit transaction'.
When I try to use the sample code from SAP (project called "order" in C:\Program Files\SAP\SAP
Business One SDK\Samples\COM DI\CSharp\05.order), it fails with the same response.
This is the code I am using (although please remember that SAP code returns the same error).
public class oOrder
{
public int DocNum { get; set; }
public string CardCode { get; set; }
public string CardName { get; set; }
public DateTime DocDate { get; set; }
public DateTime DocDueDate { get; set; }
public ArrayList DocumentLines { get; set; }
public oOrder()
{
this.DocumentLines = new ArrayList();
}
}
public class oOrderLineItem
{
public string ItemCode { get; set; }
public string ItemDescription { get; set; }
public double Quantity { get; set; }
}
From the calling code:
// Create an order object
oOrder oOrder = new oOrder();
// Populate order object with values
oOrder.DocNum = 79054;
oOrder.CardCode = "SAF";
oOrder.CardName = "SAFEWAY";
oOrder.DocDate = DateTime.Now;
oOrder.DocDueDate = DateTime.Now.AddDays(4);
// Create line item 1, populate with values
oOrderLineItem oOrderLineItem1 = new oOrderLineItem();
oOrderLineItem1.ItemCode = "HOB";
oOrderLineItem1.ItemDescription = "HONEY BUNCH GOLDEN GRAPE 12 PINT";
oOrderLineItem1.Quantity = 1;
// Create line item 2, populate with values
oOrderLineItem oOrderLineItem2 = new oOrderLineItem();
oOrderLineItem2.ItemCode = "YPR";
oOrderLineItem2.ItemDescription = "YELLOW PEAR 12 HALF PINT";
oOrderLineItem2.Quantity = 2;
// Add line items to the order object
oOrder.DocumentLines.Add(oOrderLineItem1);
oOrder.DocumentLines.Add(oOrderLineItem2);
int lRetCode = di.AddOrderToSAP(oOrder);
The code that attempts to add the order to B1"
public int AddOrderToSAP(oOrder oOrder)
{
sapCompany = new Company();
// Set connection properties
sapCompany.Server = databaseServer;
sapCompany.CompanyDB = databaseName;
sapCompany.LicenseServer = diServerLicenseServer;
sapCompany.DbUserName = databaseUserName;
sapCompany.DbPassword = databasePassword;
sapCompany.language = SAPbobsCOM.BoSuppLangs.ln_English;
sapCompany.UserName = companyUserName;
sapCompany.Password = companyPassword;
sapCompany.UseTrusted = true;
// Try to connect
lRetCode = sapCompany.Connect();
sapOrder = ((SAPbobsCOM.Documents)(sapCompany.GetBusinessObject
(SAPbobsCOM.BoObjectTypes.oOrders)));
sapOrder.DocNum = oOrder.DocNum;
sapOrder.CardCode = oOrder.CardCode;
sapOrder.CardName = oOrder.CardName;
sapOrder.DocDate = oOrder.DocDate;
sapOrder.DocDueDate = oOrder.DocDueDate;
bool firstLineItemAdded = false;
foreach (oOrderLineItem oOrderLineItem in oOrder.DocumentLines)
{
if (firstLineItemAdded)
{
sapOrder.Lines.Add();
}
sapOrder.Lines.ItemCode = oOrderLineItem.ItemCode;
sapOrder.Lines.ItemDescription = oOrderLineItem.ItemDescription;
sapOrder.Lines.Quantity = oOrderLineItem.Quantity;
if (!firstLineItemAdded)
{
firstLineItemAdded = true;
}
}
lRetCode = sapOrder.Add(); // Try to add the orer to the database
sapCompany.Disconnect();
if (lRetCode != 0)
{
sapCompany.GetLastError(out lErrCode, out sErrMsg);
}
return lRetCode;
}
If you have any ideas about why the system isn't accepting an order from this code, or from the
standard sample code provided by SAP, please let me know.
Thank you,
Mike
Dear Michael Gurevich,
Please try to remove or comment the change of SBO_SP_TransactionNotification then try to add the order again.
Best Regards
Jane Jing
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Michael Gurevich,
The default SBO_SP_TransactionNotification as follows:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER proc [dbo].[SBO_SP_TransactionNotification]
@object_type nvarchar(20), -- SBO Object Type
@transaction_type nchar(1), -- [A]dd, <u>pdate, [D]elete, [C]ancel, C[L]ose
@num_of_cols_in_key int,
@list_of_key_cols_tab_del nvarchar(255),
@list_of_cols_val_tab_del nvarchar(255)
AS
begin
-- Return values
declare @error int -- Result (0 for no error)
declare @error_message nvarchar (200) -- Error string to be displayed
select @error = 0
select @error_message = N'Ok'
--------------------------------------------------------------------------------------------------------------------------------
-- ADD YOUR CODE HERE
--------------------------------------------------------------------------------------------------------------------------------
-- Select the return values
select @error, @error_message
end
Best Regards
Jane Jing
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Michael Gurevich,
Could you test if can add the order by B1 client but not via SDK?
Please check if there is any modify in store procedure SBO_SP_TransactionNotificaion,
If have then try to remove the change to check if the issue still exists.
Best Regards
Jane Jing
SAP Business One Forums team
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Michael Gurevich,
If you add the order with automatically assigns the number to the document, then you don' t need to set the DocNum
property :oOrder.DocNum = 79054.
If you add the order with manual number, then when you set oOrder.DocNum = 79054, you also need to set the value of the HandWritten property is tYES and also set the Series property to -1.
Best Regards
Jane Jing
SAP Business One Forums team
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Jane!
I have updated the code as you suggested, and still experience ErrCode 1.
If I try to add an order with a DocNum that already exists, we get this error:
This entry already exists in the following tables (ODBC -2035)
So that's good... But adding an order that doesn't exist returns ErrCode 1.
sapOrder.DocNum = oOrder.DocNum;
sapOrder.CardCode = oOrder.CardCode;
sapOrder.CardName = oOrder.CardName;
sapOrder.DocDate = oOrder.DocDate;
sapOrder.DocDueDate = oOrder.DocDueDate;
sapOrder.HandWritten = SAPbobsCOM.BoYesNoEnum.tYES;
sapOrder.Series = -1;
Please let me know what I can try next.
Thank you,
Mike
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.