BPM custom code insert into table before exception raised

Hey,

I’m after some help with Exceptions and table inserts in a data-directive.

My data-directive runs In-Transaction and my flow is: conditions → custom code → raise exception.

The raise exception however prevents the row insert into my UD table presumably because it terminates on error. So my question is, how can I handle this where I need to prevent a row being created on the PODetail table (handled by the raise exception) and information being entered into a UD table (custom code).

The other strange thing is my custom code runs for emailing information out for example even with the raise exception - just not for the row insert on UD106.

Custom Code:

using (var txScope = IceContext.CreateDefaultTransactionScope())
{    
  foreach (var recPODet in (from row in ttPODetail 
      select row))
      {
       /* Update UD Record */
               UD106 newRow = new UD106();
               Db.UD106.Insert(newRow);
               newRow.Company = Session.CompanyID;
               newRow.Key1 = recPODet.PONUM.ToString();
               newRow.Key2 = recPODet.POLine.ToString();
               newRow.Key3 = Guid.NewGuid().ToString();
               newRow.ShortChar01 = personname;
       }
  
      Db.Validate();
      txScope.Complete();
}

Thanks!

Running In-Transaction means that changes to the database can be rolled back if there are errors. I assume that by raising an exception, the system calls roll back (undo) instead of commit (save). Email is external to the database and is not required to respect the Transaction.

Thanks for clarifying Jonathan. I thought that’d be the case!

Is there a way around doing this so that I can insert into the UD table but then prevent the save on the PODetail? I was wondering if this could be acheived within the custom code block but I wouldn’t know where to begin with it.

I don’t know if there’s a way around it in-transaction. That is not something I’ve ever tried or looked into.

No problem, thank you for your replies!

Call a function to add your ud row, and do not call it inside that transaction scope you made.