Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Unable to add order to B1. Please help.


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

            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

            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.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


            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,


Former Member
Former Member replied

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

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question