bwhite
June 10, 2024, 5:43pm
1
I have a Gateway Tag Change Script in a project. (8.1.17)
I need to get the new value of the tag that changed. I have tried several things:
newValue.getValue().value
newValue.value
event.newValue.getValue().value
event.newValue.value
Can anyone help with the correct syntax?
According to the docs: Gateway Event Scripts | Ignition User Manual
you want
newValue.getValue()
2 Likes
lrose
June 10, 2024, 5:47pm
3
It would be:
newValue.getValue()
or
newValue.value
Either will work, the second is more performant.
What leads you to believe that it isn't returning the correct value, or that this is the incorrect syntax?
bwhite
June 10, 2024, 5:59pm
4
I was getting an error about 'none' type, I believe. I've changed it so I'll have to wait until it triggers again to see the exact error.
lrose
June 10, 2024, 6:10pm
5
Generally, this is due to not checking for initialChange.
if not initialChange and newValue:
#your code here
Odd that the official syntax is currentValue
on tag event scripts but newValue
in gateway tag change scripts. To your original question, we use currentValue.value
in our gateway tag change scripts and that has been working fine.
bwhite
June 10, 2024, 6:15pm
7
I have
"""
if not initialChange and newValue.value ==1:
"""
Just for kicks, try changing it to:
if not initialChange and currentValue.value == 1:
lrose
June 10, 2024, 6:29pm
9
So, that should then be:
if not initialChange and newValue and newValue.value == 1:
#your code
if newValue
is none, then you will still get an error, so you should check that it is not none prior to using it.
bwhite
June 10, 2024, 6:40pm
10
How could it be none? It's a boolean tag. If it gets to the tag change script, then it can read the tag, right?
lrose
June 10, 2024, 6:43pm
11
newValue
isn't a boolean though, its a QualifiedValue, and it is completely possible that a None
value is sent to the tag change. This is always the case on initialChange for the previousValue.
2 Likes
bwhite
June 10, 2024, 6:46pm
12
I'll try that and see if that works! Thank you
bwhite
June 12, 2024, 12:24pm
13
This is what worked:
if not initialChange and newValue.value:
1 Like