# Use derived tag to read/write to database value

**URL:** <https://forum.inductiveautomation.com/t/use-derived-tag-to-read-write-to-database-value/74969>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [June 13, 2023, 4:57pm UTC](https://forum.inductiveautomation.com/t/use-derived-tag-to-read-write-to-database-value/74969 "2023-06-13T16:57:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clinton\_Williams](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@Clinton\_Williams](https://forum.inductiveautomation.com/u/Clinton_Williams)\
**Post date:** [June 13, 2023, 4:57pm UTC](https://forum.inductiveautomation.com/t/use-derived-tag-to-read-write-to-database-value/74969/1 "2023-06-13T16:57:43Z")

</div>

I'm trying to set up a Derived Tag and use the "Read Expression" (i.e., getter) and "Write Expression (i.e. setter) to read/write to a database value.

I'm having trouble with the Write Expression.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/9/59de14f16afb94f3df456572baea6215dedd83e5.png)

It calls a [runScript() expression function](https://docs.inductiveautomation.com/display/DOC81/runScript), which calls db.setDeviceField()  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/3/e38c70cd2f4a72e578fdd44a27c680455977aba9.png)

But every time I try to write to the derived tag, I get "Bad\_ReferenceNotFound"  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/4/c488aaca0431f53906abaea2009aac9ae779db3c.png)

I've already tried changing the [Gateway Scripting Project](https://docs.inductiveautomation.com/display/DOC80/Project+Library#ProjectLibrary-GatewayScriptingProject) but nothing seems to resolve the reference not found error. What am I missing?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 13, 2023, 5:07pm UTC](https://forum.inductiveautomation.com/t/use-derived-tag-to-read-write-to-database-value/74969/2 "2023-06-13T17:07:28Z")

</div>

~~That is not how derived tags are meant to be used.  
You should be doing an out-of-band side effect via a tag event script.~~

This is a bad idea. We used to have a concept of a "database" tag provider and intentionally removed it from the product. Synchronization is an endless source of headaches.

---

<div class="post-metadata">

**Author:** ![Clinton\_Williams](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@Clinton\_Williams](https://forum.inductiveautomation.com/u/Clinton_Williams)\
**Post date:** [June 13, 2023, 7:29pm UTC](https://forum.inductiveautomation.com/t/use-derived-tag-to-read-write-to-database-value/74969/3 "2023-06-13T19:29:08Z")

</div>

I've got a solution working for keeping reads synchronized, but it would be nice to be able to read and write from the same tag so I can treat it like any other OPC tag in Vision/Perspective.

Do you have any suggestions?
