# Gateway Tag Change Script Not Firing

**URL:** <https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-firing/77072>\
**Category:** Ignition\
**Tags:** vision, scripting, ignition80\
**Created:** [July 28, 2023, 3:09pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-firing/77072 "2023-07-28T15:09:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mason\_Stevens](https://avatars.discourse-cdn.com/v4/letter/m/edb3f5/32.png) [@Mason\_Stevens](https://forum.inductiveautomation.com/u/Mason_Stevens)\
**Post date:** [July 28, 2023, 3:09pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-firing/77072/1 "2023-07-28T15:09:54Z")

</div>

Hey all. I've been trying my hand at utilizing tag change scripts to write values from query tags down into the OPC tags from the controller. I very quickly ran into an issue, though, as none of my scripts will fire. I tried multiple iterations of my real script before deciding to make a simple testing setup to diagnose the issue. The testing script and setup is as follows:

```auto
if newValue.value:	
	read = system.tag.readBlocking("[default]R300/test/Read")
	arg = read.value
	system.tag.writeBlocking("[default]R300/test/Write",arg)

```

I created 3 dummy tags to go with the script:

- Trigger: (boolean memory tag)
- Read: (integer query tag)
- Write: (integer memory tag)

The script runs upon a change in Trigger, and obviously my goal is to read the value from the Read tag and write it to the Write tag. However, nothing seems to allow me to do this. I have tried removing the line:

```auto
if newValue.value:

```

as well as try a completely explicit write script with nothing else:

```auto
system.tag.writeBlocking("[default]R300/test/Write",123)

```

Additionally, I tried using system.tag.writeSynchronus, as I saw it recommended in a similar thread.

I have a handful of tags that I want to read from and write to at once, but I cannot manage to get even this simple case to work. Any advice on this issue would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![aaronrai24](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/aaronrai24/32/87248_2.png) [@aaronrai24](https://forum.inductiveautomation.com/u/aaronrai24)\
**Post date:** [July 28, 2023, 3:21pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-firing/77072/2 "2023-07-28T15:21:48Z")

</div>

You need to extract the qualifiedValue as [system.tag.readBlocking](https://docs.inductiveautomation.com/display/DOC81/system.tag.readBlocking) returns a list of qualified values. Heres an example:

```auto
read = system.tag.readBlocking("[default]R300/test/Read")
arg = read[0] # extract the qualified value from this list, there should only be 1 because we are reading a single tag value` 
print arg.value

```

you can also just do: ` arg = system.tag.readBlocking("[default]R300/test/Read")[0].value`

For your [system.tag.writeBlocking](https://docs.inductiveautomation.com/display/DOC81/system.tag.writeBlocking) you should be passing a list of tag paths and list of values, like this:

```auto
system.tag.writeBlocking(["[default]R300/test/Write"],[arg])

```

---

<div class="post-metadata">

**Author:** ![Mason\_Stevens](https://avatars.discourse-cdn.com/v4/letter/m/edb3f5/32.png) [@Mason\_Stevens](https://forum.inductiveautomation.com/u/Mason_Stevens)\
**Post date:** [July 28, 2023, 3:32pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-firing/77072/3 "2023-07-28T15:32:59Z")

</div>

I've updated the script to read:

```auto
if newValue.value:	
	arg = system.tag.readBlocking("[default]R300/test/Read")[0].value
	print arg
	system.tag.writeBlocking(["[default]R300/test/Write"],[arg])

```

Unfortunately, I still see no updates to the tag. Additionally, I do not see the 'arg' value printed or any errors thrown in the console. The only indication in the console that I'm doing anything at all is the wall of project saves.

---

<div class="post-metadata">

**Author:** ![Mason\_Stevens](https://avatars.discourse-cdn.com/v4/letter/m/edb3f5/32.png) [@Mason\_Stevens](https://forum.inductiveautomation.com/u/Mason_Stevens)\
**Post date:** [July 28, 2023, 3:36pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-firing/77072/4 "2023-07-28T15:36:46Z")

</div>

Also a bit of a side question: if I was going to read multiple tags at once, would the 2nd line of your example be written as follows instead?

```auto
arg = read[0,1,2,3, ... ,n]

```

where n = (number of tags) - 1

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 28, 2023, 3:40pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-firing/77072/5 "2023-07-28T15:40:10Z")

</div>

Neither one of you should be using `print`. That isn't captured by the gateway log, only the wrapper log. I say gateway log because gateway events don't run in your designer, so they aren't going to write to the designer's console.

There's very likely some subtle error in your event code that is throwing an error (once) in the gateway log. Look there.

Aside from that, consider your architecture. Your goals sound suspiciously like some kind of recipe load operation. If so, you should not be using query tags, but scripting your queries after the trigger fires. Then writing to your tags (in one single big `system.tag.writeBlocking()`) from the result.

---

<div class="post-metadata">

**Author:** ![Mason\_Stevens](https://avatars.discourse-cdn.com/v4/letter/m/edb3f5/32.png) [@Mason\_Stevens](https://forum.inductiveautomation.com/u/Mason_Stevens)\
**Post date:** [July 28, 2023, 3:56pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-firing/77072/6 "2023-07-28T15:56:40Z")

</div>

Thank you for the insight, I was able to find an error in the gateway log that can be condensed down as follows:

"Cannot coerce value '[default]R300/test/Read' into type: interface java.util.List"

because I was missing a pair of brackets around my readBlocking argument. Fixing the bracket issue allowed me to write to the tag as initially intended, but I take your meaning regarding the query tags. The script seems functional now but I'll be sure to rewrite to include the queries directly in the script instead of using an intermediate tag for them.

Thank you both so much for the help!

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 28, 2023, 4:08pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-firing/77072/7 "2023-07-28T16:08:33Z")

</div>

This is exactly the type of process that Transaction Groups are made for, if you do not have the SQL Bridge module, then you should definitely be running the query in the script. I would recommend `system.db.runNamedQuery()`.

`system.tag.readBlocking()` takes a list of tag paths. It returns a list of QualifiedValues maintaining the order the tag paths were passed in.

You can the. Reference the value of those tags by index in the list.
