# Gateway tag change script cannot hold the value

**URL:** <https://forum.inductiveautomation.com/t/gateway-tag-change-script-cannot-hold-the-value/77481>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [August 4, 2023, 8:53pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-cannot-hold-the-value/77481 "2023-08-04T20:53:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbai1](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@mbai1](https://forum.inductiveautomation.com/u/mbai1)\
**Post date:** [August 4, 2023, 8:53pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-cannot-hold-the-value/77481/1 "2023-08-04T20:53:08Z")

</div>

hello,

In my gateway tag change script, I have a if condition to turn a external indicator on and off, however, I found that the indicator tag will be off after sometimes when it being turn on. The indicator tag cannot hold the on staus for too long, it will be written to 0 ( off) after sometimes, please help to see where I may do wrong.  
gateway script:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/c/7cc932cc2df372359423743e982007c036169e87.png)

---

<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:** [August 4, 2023, 8:56pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-cannot-hold-the-value/77481/2 "2023-08-04T20:56:02Z")

</div>

Please post code - not pictures of code - so we can copy and edit in our answers. Use the \</\> code formatting button to preserve indents and syntax highlighting.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 4, 2023, 8:58pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-cannot-hold-the-value/77481/3 "2023-08-04T20:58:26Z")

</div>

`writeBlocking` expects a LIST of tags and a LIST of values to go with those tags. You need to wrap your values in square brackets like you did for the tags paths.  
Frankly I'd expect this to not work at all. Check your logs for errors, I'm sure you'll find clues there.

---

<div class="post-metadata">

**Author:** ![mbai1](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@mbai1](https://forum.inductiveautomation.com/u/mbai1)\
**Post date:** [August 4, 2023, 8:58pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-cannot-hold-the-value/77481/4 "2023-08-04T20:58:42Z")

</div>

```auto
if newValue.quality.isGood():
  zone_id = system.tag.read(str(event.tagPath.getParentPath()) + '/ZoneToMonitor').value
  if zone_id != 0 and newValue.value :
    system.tag.writeBlocking(["Banner/_Banner_/UnitId 1/1_Banner17-1_Banner48/1_Banner46"],33792)
  elif zone_id != 0 and newValue.value ==0 and IAPI/Missions/MissionSubscriber0/MissionState !=4:
    system.tag.writeBlocking(["Banner/_Banner_/UnitId 1/1_Banner17-1_Banner48/1_Banner46"],1023)  

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 4, 2023, 9:01pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-cannot-hold-the-value/77481/5 "2023-08-04T21:01:11Z")

</div>

Also, what is `IAPI/Missions/MissionSubscriber0/MissionState !=4` ?  
Unless this is defined in your project library (but that path says it's not), it will also raise an error as it's not defined anywhere in this script's scope.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 6, 2023, 6:03am UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-cannot-hold-the-value/77481/6 "2023-08-06T06:03:25Z")

</div>

This is the division of 5 variables that don't appear to be defined anywhere.

It looks like it's supposed to be comparing 4 to a tag's value, so system.tag.readBlocking should be used to read the tag path

---

<div class="post-metadata">

**Author:** ![mbai1](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@mbai1](https://forum.inductiveautomation.com/u/mbai1)\
**Post date:** [August 14, 2023, 7:47pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-cannot-hold-the-value/77481/7 "2023-08-14T19:47:39Z")

</div>

hello, after I wrap the values in square brackets and delete the `IAPI/Missions/MissionSubscriber0/MissionState !=4`, i still have the issue that `"Banner/_Banner_/UnitId 1/1_Banner17-1_Banner48/1_Banner46" ` will switch to 0 after sometimes. This problem raise no error in the log right now.

Similarily, I running into same issue with other scripts that write in the tag Editor.  
Basically, when a MissionState equals to 4, it will trigger the LED tag to 2048 to flashing red, however, the value of 2048 can't hold for too long (`while MissionState =4`) in `"Banner/_Banner_/UnitId 1/1_Banner17-1_Banner48/1_Banner46" `. I wrote a value changed script in **Mission Sate tag editor** ：

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	if currentValue.value==4:
		system.tag.writeBlocking(["[default]Banner/_Banner_/UnitId 1/1_Banner17-1_Banner48/1_Banner46"], [2048])
	if currentValue.value!=4:
		system.tag.writeBlocking(["[default]Banner/_Banner_/UnitId 1/1_Banner17-1_Banner48/1_Banner46"], [0])

```

In the log, i got the following error:  
`Error writing tags Error writing to tag '[default]IAPI/Missions/MissionSubscriber0/WatchMissionID': Bad("Bad_DataUnavailable: Expected data is unavailable for the requested time range due to an un-mounted volume.")`

please help, thanks!

---

<div class="post-metadata">

**Author:** ![mbai1](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@mbai1](https://forum.inductiveautomation.com/u/mbai1)\
**Post date:** [August 14, 2023, 7:53pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-cannot-hold-the-value/77481/8 "2023-08-14T19:53:00Z")

</div>

hello, after I wrap the values in square brackets and delete the `IAPI/Missions/MissionSubscriber0/MissionState !=4`, i still have the issue that `"Banner/_Banner_/UnitId 1/1_Banner17-1_Banner48/1_Banner46" `will switch to 0 after sometimes. This problem raise no error in the log right now.

Similarily, I running into same issue with other scripts that write in the tag Editor.  
Basically, when a MissionState equals to 4, it will trigger the LED tag to 2048 to flashing red, however, the value of 2048 can't hold for too long in the tag: `"Banner/_Banner_/UnitId 1/1_Banner17-1_Banner48/1_Banner46"` . I wrote a value changed script in **Mission Sate tag editor** ：

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	if currentValue.value==4:
		system.tag.writeBlocking(["[default]Banner/_Banner_/UnitId 1/1_Banner17-1_Banner48/1_Banner46"], [2048])
	if currentValue.value!=4:
		system.tag.writeBlocking(["[default]Banner/_Banner_/UnitId 1/1_Banner17-1_Banner48/1_Banner46"], [0])

```

In the log, i got the following error:  
`Error writing tags Error writing to tag '[default]IAPI/Missions/MissionSubscriber0/WatchMissionID': Bad("Bad_DataUnavailable: Expected data is unavailable for the requested time range due to an un-mounted volume.")`

please help, thanks!

---

<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:** [August 14, 2023, 8:41pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-cannot-hold-the-value/77481/10 "2023-08-14T20:41:58Z")

</div>

You should call into support and let them look over your shoulder.

This:

```auto
Error writing tags Error writing to tag '[default]IAPI/Missions/MissionSubscriber0/WatchMissionID': 
Bad("Bad_DataUnavailable: Expected data is unavailable for the requested time range due to an un-mounted volume.")

```

Seems bad.

Especially considering that tag path is completely different than the one you're working with.

---

<div class="post-metadata">

**Author:** ![mbai1](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@mbai1](https://forum.inductiveautomation.com/u/mbai1)\
**Post date:** [August 14, 2023, 9:24pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-cannot-hold-the-value/77481/11 "2023-08-14T21:24:38Z")

</div>

sorry for the inconvenience, I have updated the code, please check, thanks

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 15, 2023, 8:14am UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-cannot-hold-the-value/77481/12 "2023-08-15T08:14:47Z")

</div>

You should first try to find what is trying to write to `'[default]IAPI/Missions/MissionSubscriber0/WatchMissionID'`.  
Then find if anything else is writing to `"[default]Banner/_Banner_/UnitId 1/1_Banner17-1_Banner48/1_Banner46"`.  
I'm not sure how to do that.

You can write your value changed script like this to make it clearer what's going on:

```python
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	if currentValue.value == 4:
		value = 2048
	else:
		value = 0
	system.tag.writeBlocking(["[default]Banner/_Banner_/UnitId 1/1_Banner17-1_Banner48/1_Banner46"], [value])

```
