# Function updating DB table

**URL:** <https://www.epiusers.help/t/function-updating-db-table/101386>\
**Category:** Kinetic ERP\
**Created:** [April 4, 2023, 7:18pm UTC](https://www.epiusers.help/t/function-updating-db-table/101386 "2023-04-04T19:18:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![datadaddy](https://www.epiusers.help/user_avatar/www.epiusers.help/datadaddy/32/55900_2.png) [@datadaddy](https://www.epiusers.help/u/datadaddy)\
**Post date:** [April 4, 2023, 7:18pm UTC](https://www.epiusers.help/t/function-updating-db-table/101386/1 "2023-04-04T19:18:14Z")

</div>

I am attempting to save a calculated value in a function following this post:

> [@Epicor Functions - DB table update](https://www.epiusers.help/t/epicor-functions-db-table-update/82855):
>
> I have a function that is utilizing a custom code widget to update a DB table. I am moving data from a system field to a new UD field because they needed a larger field. (I know I could do this with Business Objects, but in this case, I am potentially updating some older records which sometimes prevents this update.) int counter = 0; foreach (var dr in Db.OrderDtl.Where(x =\> x.Reference != x.Reference\_c && x.Reference\_c==string.Empty)) { counter++; dr.Reference\_c = dr.Ref…

My functions is set to requires transactions and library is set to DB read/write  
I also have added the assembly reference to Erp.Internal.Lib.CCredChk.dll

The code syntax check has no errors except this one:  
`The type 'TransactionScope' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Transactions.Local,`

but when I go to add the reference is does not appear in the list of available assemblies

This occurs on the line:  
` using(var txScope = Ice.IceContext.CreateDefaultTransactionScope())`

thx

---

<div class="post-metadata">

**Author:** ![andrew.johnson](https://www.epiusers.help/user_avatar/www.epiusers.help/andrew.johnson/32/61226_2.png) [@andrew.johnson](https://www.epiusers.help/u/andrew.johnson)\
**Post date:** [April 4, 2023, 7:21pm UTC](https://www.epiusers.help/t/function-updating-db-table/101386/2 "2023-04-04T19:21:45Z")

</div>

In my experience, if your function has the ‘Require Transaction’ option checked, you shouldn’t need to wrap your code in the transaction scope manually. That checkbox does the work for you.

The combination of that option checked, plus your code, might be causing a conflict.

---

<div class="post-metadata">

**Author:** ![datadaddy](https://www.epiusers.help/user_avatar/www.epiusers.help/datadaddy/32/55900_2.png) [@datadaddy](https://www.epiusers.help/u/datadaddy)\
**Post date:** [April 4, 2023, 7:25pm UTC](https://www.epiusers.help/t/function-updating-db-table/101386/3 "2023-04-04T19:25:46Z")

</div>

I previously did not have it checked, tried turning it on because of the error

---

<div class="post-metadata">

**Author:** ![andrew.johnson](https://www.epiusers.help/user_avatar/www.epiusers.help/andrew.johnson/32/61226_2.png) [@andrew.johnson](https://www.epiusers.help/u/andrew.johnson)\
**Post date:** [April 4, 2023, 7:29pm UTC](https://www.epiusers.help/t/function-updating-db-table/101386/4 "2023-04-04T19:29:32Z")

</div>

Try removing the `using(var txScope...)` statement in your code, but leave the checkbox checked.

> [@Do I need to use a TransactionScope inside an Epicor Function?](https://www.epiusers.help/t/do-i-need-to-use-a-transactionscope-inside-an-epicor-function/80979):
>
> Should I be using a transaction scope in c# written inside an Epicor function? Something like: using (var txScope = IceContext.CreateDefaultTransactionScope()){ ~Insert Code Here~ Db.Validate(); // Complete the transaction txScope.Complete(); } If so how to I get Db.Validate to work as I get an error message when trying to refer to the DB from a function like that. Thanks.

---

<div class="post-metadata">

**Author:** ![datadaddy](https://www.epiusers.help/user_avatar/www.epiusers.help/datadaddy/32/55900_2.png) [@datadaddy](https://www.epiusers.help/u/datadaddy)\
**Post date:** [April 4, 2023, 7:42pm UTC](https://www.epiusers.help/t/function-updating-db-table/101386/5 "2023-04-04T19:42:14Z")

</div>

okay, that get’s rid of the error (of course), now to see if it actually updates the data, thx

---

<div class="post-metadata">

**Author:** ![datadaddy](https://www.epiusers.help/user_avatar/www.epiusers.help/datadaddy/32/55900_2.png) [@datadaddy](https://www.epiusers.help/u/datadaddy)\
**Post date:** [April 4, 2023, 8:10pm UTC](https://www.epiusers.help/t/function-updating-db-table/101386/6 "2023-04-04T20:10:06Z")

</div>

Yeah, there’s something fundamentally wrong here (with me probably)

I created a new function with a simple test,  
grab an order line (orderNum and orderLine are input parms to my function)  
update one of my user defined fields…

nothing changes

this is my code:

```auto
var orderDetails = Db.OrderDtl.Where
   (k => k.OrderNum == orderNum && k.OrderLine == orderLine &&
    k.Company == this.callContextClient.CurrentCompany);
    
var orderDetailsRow = orderDetails.First();

orderDetailsRow.AddOrderComm_c = "test add order comments";

```

I call the function via Rest API Helper, I know I’m finding the order line because I stuff debug strings in my output (response parm)

Requires Transactions is on, Function library is read/write

---

<div class="post-metadata">

**Author:** ![klincecum](https://www.epiusers.help/user_avatar/www.epiusers.help/klincecum/32/100137_2.png) [@klincecum](https://www.epiusers.help/u/klincecum)\
**Post date:** [April 4, 2023, 8:17pm UTC](https://www.epiusers.help/t/function-updating-db-table/101386/7 "2023-04-04T20:17:41Z")

</div>

You need to call save changes on the Db Object.

Also, on the Tables tab, make sure that specific table is selected to be updatable.

---

<div class="post-metadata">

**Author:** ![datadaddy](https://www.epiusers.help/user_avatar/www.epiusers.help/datadaddy/32/55900_2.png) [@datadaddy](https://www.epiusers.help/u/datadaddy)\
**Post date:** [April 4, 2023, 8:26pm UTC](https://www.epiusers.help/t/function-updating-db-table/101386/8 "2023-04-04T20:26:15Z")

</div>

omg, always the simplest things to overlook, thx, that helped
