cancel
Showing results for 
Search instead for 
Did you mean: 

Transaction Rollback not working

rajesh_khater
Active Participant
0 Kudos

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.

  1. void SBO_Application_FormDataEvent(ref SAPbouiCOM.BusinessObjectInfo BusinessObjectInfo, out bool BubbleEvent) 
  2.     BubbleEvent = true; 
  3.     if (BusinessObjectInfo.FormTypeEx == "141" 
  4.         && (BusinessObjectInfo.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD || BusinessObjectInfo.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_UPDATE) 
  5.         && BusinessObjectInfo.BeforeAction == true) 
  6.     { 
  7.         oCompany.StartTransaction(); 
  8.     } 
  9.     if (BusinessObjectInfo.FormTypeEx == "141" 
  10.         && (BusinessObjectInfo.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD || BusinessObjectInfo.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_UPDATE) 
  11.         && BusinessObjectInfo.BeforeAction == false) 
  12.     { 
  13.         if (BusinessObjectInfo.ActionSuccess) 
  14.         { 
  15.             try 
  16.             { 
  17.                 string nullStr = null
  18.                 nullStr.Contains("ABCD"); 
  19.                 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit); 
  20.             } 
  21.             catch (Exception ex) 
  22.             { 
  23.                 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack); 
  24.                 MessageBox.Show(ex.Message); 
  25.             } 
  26.         } 
  27.     } 

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

Thanks.

I am trying this on 9.1 PL 00.

Can other experts try this code and let me know if they get similar results?

A lot of threads in this forum mention that starting a global transaction in the Before Action, and rolling back in the After Action is treated as a single transaction and should therefore work.

But some thread also suggests that it will not work.

This is urgent.

Accepted Solutions (0)

Answers (1)

Answers (1)

maik_delly
Active Contributor
0 Kudos

Hi Rajesh,

transaction is for DI API only - meaning only transactions made by DI API can be rolled back. You are trying to roll back something you are not doing, but SBO client.

If you want to stop adding of a document in client you could use transaction notification.

regards,

Maik