Skip to Content
0
Mar 14, 2015 at 10:37 AM

Transaction Rollback not working

44 Views

Hi,

In the AP Invoice Before Add event (Event = FormDataEvent, Event Type = Add or Update, Before Action = True), I am starting a transaction.

Then in After Add event, I am deliberately creating a null pointer exception (to test rollback), and in the exception handler, I am rolling back the transaction.

void SBO_Application_FormDataEvent(ref SAPbouiCOM.BusinessObjectInfo BusinessObjectInfo, out bool BubbleEvent)
{
    BubbleEvent = true;

    if (BusinessObjectInfo.FormTypeEx == "141"
        && (BusinessObjectInfo.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD || BusinessObjectInfo.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_UPDATE)
        && BusinessObjectInfo.BeforeAction == true)
    {
        oCompany.StartTransaction();
    }
    if (BusinessObjectInfo.FormTypeEx == "141"
        && (BusinessObjectInfo.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD || BusinessObjectInfo.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_UPDATE)
        && BusinessObjectInfo.BeforeAction == false)
    {
        if (BusinessObjectInfo.ActionSuccess)
        {
            try
            {
                string nullStr = null;
                nullStr.Contains("ABCD");
                oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
            }
            catch (Exception ex)
            {
                oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                MessageBox.Show(ex.Message);
            }
        }
    }
}

Still the AP Invoice gets saved in the database. What may be the issue?

Thanks.