Is it possible to call a function from custom code in a data directive (in transaction)? I am using a function to write data to a UD table to act as a change log on tables that don’t have it as an option. It will also be used to capture deleted records for which the Epicor change log does not record.
I thought I had a working solution using a standard data directive (with call function widgets) until multiple records were updated at the same time. So, it seems like in-tran data directive is where this needs to be to capture changes on multiple records updated simultaneously. I guess this makes sense as that is where Epicor’s change log is set?
Custom Code, per other threads I have seen to call the function is below. This has worked on a standard dd but not in-transaction. I tried adding clarification to the row mod to target the correct row, but that didn’t seem to help.
```<foreach (var row in ttTABLE
.Where(r => r.RowMod == “U” || r.RowMod == “A”)) // Only updated or added rows
{
var table = “TABLE”;
var tableKey1 = “test”;
var tableKey2 = “test”;
var tableKey3 = “”;
var type = “Updated”;
var Char03 = “Test”;
var Char04 = “”;
var Char05 = “”;
And for your specific issue… you can try this, but I’d recommend just turning on the Change Log for the table and using that, unless you have a specific reason.
//using System.Transactions;
try
{
using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
{
foreach (var row in ttTABLE.Where(r => r.RowMod == "U" || r.RowMod == "A")) // Only updated or added rows
{
var table = "TABLE";
var tableKey1 = "test";
var tableKey2 = "test";
var tableKey3 = "";
var type = "Updated";
var Char03 = "Test";
var Char04 = "";
var Char05 = "";
this.InvokeFunction("Library", "Function", table, tableKey1, tableKey2, tableKey3, type, Char03, Char04, Char05);
}
scope.Complete();
}
}
catch (Exception ex)
{
throw new Ice.BLException("Failed while invoking Library.Function.\n\n" + ex.ToString());
}
Thanks for the change log function. I was able to install for one of the missing the tables. That being said, deleted records are still going to be a problem since it seems that deleting records from the table (EquipPlan) also deletes the changes recorded in ChgLog. I thought I read elsewhere that this behavior is inconsistent from table to table when deleting records.
New error with the in-tran custom code. I guess how difficult is it to get a function to run in-tran? I was thinking it would be similar to a standard directive, but maybe that isn’t the case and I need to rethink other options.
I believe,
This error is created by having the Require Transaction checkbox checked in the Function. (Or not checked)
Basically you are calling something in this funciton which is triggereing another transaction and the system doesn’t like having a transaction inside a transaction.
Since you are invoking from InTran you already have an Open Transaction, and are now trying to crate another inside the function.
I thought there was an idea for external logging too so that the logs are immutable and not lost if the database is corrupted or deleted, but I can’t find it any more.