cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP B1 Service Layer

0 Kudos
519
We create a delivery with the DI API and update our sql table in the same transaction.
If the update query fails, we also rollback the delivery creation process.
We failed to run update query with Servicelayer.
We want to do these operations in a single transaction with the servicelayer. How can we do this with servicelayer.

        public string xx(string HdrId,Company oCompany, Recodset rs)
        {
            var msj = "";
            try
            {
                oCompany.StartTransaction();
                Documents doc = (Documents)oCompany.GetBusinessObject(BoObjectTypes.oDeliveryNotes);
                doc.CardCode = "C20000";
                doc.Lines.ItemCode = "A00001";
                doc.Lines.Quantity = 1;
                lRetCode = doc.Add();
                if (lRetCode != 0)
                    throw new Exception("NOT CREATED");
                else
                {
                    var sNewObjCode = "";
                    oCompany.GetNewObjectCode(out sNewObjCode);
                    rs.DoQuery(" UPDATE \"@TST_TABLE1\"  SET \"DocEntryx\" = '" + sNewObjCode + "'  WHERE \"UniqueID\" = '" + HdrId + "' ");
                    if (oCompany.InTransaction)
                        oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
                    msj = "CREATED";
                }
            }
            catch (Exception ex)
            {
                if (oCompany.InTransaction)
                    oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                msj = "ERROR (" + ex.Message + ")";
            }
            return msj;
        }




Accepted Solutions (0)

Answers (0)