# Gateway Script Tag Issue

**URL:** <https://forum.inductiveautomation.com/t/gateway-script-tag-issue/63401>\
**Category:** Ignition\
**Tags:** scripting, ignition81, perspective\
**Created:** [August 24, 2022, 3:33pm UTC](https://forum.inductiveautomation.com/t/gateway-script-tag-issue/63401 "2022-08-24T15:33:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![csilk](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@csilk](https://forum.inductiveautomation.com/u/csilk)\
**Post date:** [August 24, 2022, 3:33pm UTC](https://forum.inductiveautomation.com/t/gateway-script-tag-issue/63401/1 "2022-08-24T15:33:32Z")

</div>

I have the following gateway script:

```auto
def dura(tagPath,box):
	tag = system.tag.readBlocking(tagPath)
	if tag == 2:
		box.props.value = tag
	else:
		box.props.value = 0

```

Very simple script, if the tags value is equal to 2, then display 2 in a numeric entry field.

Then in my project, I have a button with the following script:

```auto
	startTime = "[default]Timesheet/startTime"
	box = self.getSibling("startTime1")
	message.dura(startTime,box)

```

` startTime` is the tag that is being read in the gateway script and `box` is the numeric entry field where the value 2 should be displayed.

Currently, the tag does have a value if 2. So, in theory, a value of 2 should be displayed.. but a 0 is being displayed. I can read the tag in correctly in the gateway script, but every time I use the tag in a conditional statement, it seems as if the value isn't being read..

I tried to just use the value attribute of the tag, but I get an error saying

> 'str' object has no attribute 'value'

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [August 24, 2022, 3:36pm UTC](https://forum.inductiveautomation.com/t/gateway-script-tag-issue/63401/2 "2022-08-24T15:36:52Z")

</div>

`tag = system.tag.readBlocking(tagPath)[0].value`

---

<div class="post-metadata">

**Author:** ![csilk](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@csilk](https://forum.inductiveautomation.com/u/csilk)\
**Post date:** [August 24, 2022, 3:41pm UTC](https://forum.inductiveautomation.com/t/gateway-script-tag-issue/63401/3 "2022-08-24T15:41:25Z")

</div>

Added this and am still getting the same result

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [August 24, 2022, 3:45pm UTC](https://forum.inductiveautomation.com/t/gateway-script-tag-issue/63401/4 "2022-08-24T15:45:01Z")

</div>

You need to do some hunting then. Try logging the value and type of tag before the comparison.

Add something like:

```auto
# If you're running in a gateway context, this should show up on the webpage log viewer.
_logger = system.util.getLogger('script debug')
_logger.info(tag)
_logger.info(type(tag))

```

---

<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:** [August 24, 2022, 3:45pm UTC](https://forum.inductiveautomation.com/t/gateway-script-tag-issue/63401/5 "2022-08-24T15:45:29Z")

</div>

You said **gateway** script, but you’re trying to interact with components. Exactly where is this script defined?

---

<div class="post-metadata">

**Author:** ![csilk](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@csilk](https://forum.inductiveautomation.com/u/csilk)\
**Post date:** [August 24, 2022, 3:47pm UTC](https://forum.inductiveautomation.com/t/gateway-script-tag-issue/63401/6 "2022-08-24T15:47:43Z")

</div>

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

Here is where the script resides.

The script is called when a button is clicked in my project.

---

<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:** [August 24, 2022, 3:53pm UTC](https://forum.inductiveautomation.com/t/gateway-script-tag-issue/63401/7 "2022-08-24T15:53:19Z")

</div>

Okay, that makes more sense.

Given that, I _would_ expect this variation of your original script to work:

```auto
def dura(tagPath,box):
	tag = system.tag.readBlocking(tagPath)[0].value
	if tag == 2:
		box.props.value = tag
	else:
		box.props.value = 0

```

What error are you getting from that, if any?

---

<div class="post-metadata">

**Author:** ![csilk](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@csilk](https://forum.inductiveautomation.com/u/csilk)\
**Post date:** [August 24, 2022, 3:54pm UTC](https://forum.inductiveautomation.com/t/gateway-script-tag-issue/63401/8 "2022-08-24T15:54:38Z")

</div>

I am not receiving an error, the problem is that the conditional statement is returning a 0 when the value of the tag is, in fact, 2. So, the conditional statement should return a 2, rather than a 0.

---

<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:** [August 24, 2022, 3:55pm UTC](https://forum.inductiveautomation.com/t/gateway-script-tag-issue/63401/9 "2022-08-24T15:55:57Z")

</div>

I would then echo @zacht’s suggestion to log the data type of the value; perhaps it’s a string when you’re comparing it against an int? Python won’t do any automatic type coercion.

---

<div class="post-metadata">

**Author:** ![csilk](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@csilk](https://forum.inductiveautomation.com/u/csilk)\
**Post date:** [August 24, 2022, 4:01pm UTC](https://forum.inductiveautomation.com/t/gateway-script-tag-issue/63401/10 "2022-08-24T16:01:25Z")

</div>

Got it, had to change it to an int.
