# Issue writing value to tag in script

**URL:** <https://forum.inductiveautomation.com/t/issue-writing-value-to-tag-in-script/82745>\
**Category:** Ignition\
**Created:** [December 5, 2023, 8:51pm UTC](https://forum.inductiveautomation.com/t/issue-writing-value-to-tag-in-script/82745 "2023-12-05T20:51:50Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 5, 2023, 10:38pm UTC](https://forum.inductiveautomation.com/t/issue-writing-value-to-tag-in-script/82745/3 "2023-12-05T22:38:47Z")

</div>

Try the following:

```auto
tank_sel = event.source.parent.tank # 1
tagPath = '[default]Filler_Data/DF2_SOURCE_TANK' # 2
sourceTank = system.tag.readBlocking([tagPath]) # 3

if sourceTank[0].value: # 4
    output = 0
else:
    output = 2 ** (tank_sel - 1) # 5

system.tag.writeBlocking([tagPath], [output]) # 6

```

Explanation:

1. Original code.
2. Readability improvement.
3. readBlocking expects a list of tag paths. (It does work with only one value not in a list but it's not documented and _could_ change in a future version.) readBlocking returns a list of all the "qualified values" (value, OPC quality, timestamp).
4. Get the value (using `.value`) of the first (and, in this case, only) returned tag. The `> 0` can be omitted because `if` returns `True` for any non-zero value.
5. Your output value for tanks 1, 2, 3, 4 is 1, 2, 4, 8 so use the exponent to set the value in one line.
6. As with readBlocking, writeBlocking requires lists of tag paths and values.

I think your basic problem was that you were checking the **qualified** tag where you needed to check `.value`.

See this part of the manual:

[https://docs.inductiveautomation.com/display/DOC81/Reading+and+Writing+to+Tags#ReadingandWritingtoTags-ManualTagReads](https://docs.inductiveautomation.com/display/DOC81/Reading+and+Writing+to+Tags#ReadingandWritingtoTags-ManualTagReads)

---

_[View the full topic](https://forum.inductiveautomation.com/t/issue-writing-value-to-tag-in-script/82745)._
