Transaction Scope Error in Custom Code

I am working on some custom code and getting the following error:

image

We have this exact code working elsewhere in our system. But, I cannot create new bpms using this same code nor can I edit the existing ones as they will start posting this same error. I also see that System.Transactions is listed in the references section by default shown in the screen shot below:

image

Why would I be receiving this error now?

Steps to Recreate Error:

  1. Load at least one row into the UD01 table
  2. Create a In-Transaction Data Directive for UD01
  3. Create the following in designer

image

  1. Create the following condition

image

  1. Paste the following into the custom code block
  2. using (var txScope = IceContext.CreateDefaultTransactionScope())
    {
    foreach(var UD01 in (from row in Db.UD01 select row))
    {
    Db.UD01.Delete(UD01);
    }
    Db.Validate();
    txScope.Complete();

}
7. Check the syntax in the custom block and you should get the same error.
If you save and activate this bpm it’ll error the first time it runs then refuse to operate after.

The use case for this is to allow end users to delete items out of a UD table as needed.

See this thread.

Also, you could just use the BO to do the delete, in a BPM it would be something like this.

using ( var service = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD05SvcContract>( this.Db ))
{
	service.DeleteByID(Key1Value,Key2Value,Key3Value,Key4Value,Key5Value);
}
1 Like

When trying to run the code you supplied in either a data directive or method directive I get errors for the keys:

image

I also tried using dsUD05Row.Key2 as context with the same result. Any idea what I can do to fix this?

As for the thread you linked me we are in the gov cloud so we do not have access to get things installed on our instance. I have reached out to cloud services to see if they can implement this fix.

Thanks for the recommendations!

I run a simple delete custom code on my UDs all the time. I have been reusing this bit of code forever:

// step through each row of results
foreach (var xRow in (from ttResults_Row in queryResultDataset.Results where ttResults_Row.Calculated_MyCheck == true select ttResults_Row))
{
     using (Ice.Contracts.UD09SvcContract mySvc =  Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD09SvcContract>(Db))
       {
       mySvc.DeleteByID(xRow.UD09_Key1, xRow.UD09_Key2, xRow.UD09_Key3, xRow.UD09_Key4, xRow.UD09_Key5);
       }
}
1 Like

The “KeyXValue” references are placeholders. You have to change those to whatever references you are using in your BPM.
In your BPM specifically it would look something like this.

using ( var service = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD01SvcContract>( this.Db ))
	{
		foreach( var UD01 in ( from row in Db.UD01 select row))
		{
			service.DeleteByID(UD01.Key1,UD01.Key2,UD01.Key3,UD01.Key4,UD01.Key5);
		}
	}
2 Likes