# If Condition in Tag Change Script issue

**URL:** <https://forum.inductiveautomation.com/t/if-condition-in-tag-change-script-issue/76196>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [July 11, 2023, 3:15pm UTC](https://forum.inductiveautomation.com/t/if-condition-in-tag-change-script-issue/76196 "2023-07-11T15:15:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mariusz\_Balon](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@Mariusz\_Balon](https://forum.inductiveautomation.com/u/Mariusz_Balon)\
**Post date:** [July 11, 2023, 3:15pm UTC](https://forum.inductiveautomation.com/t/if-condition-in-tag-change-script-issue/76196/1 "2023-07-11T15:15:33Z")

</div>

Hi All,

Sorry for a newbie question. I need to modify parameters via reference tags in the UDT using Tag Change script.  
It works fine without ‘if’ conditioning, however once ‘if cur.value is True: ’ is enabled in the script ifs not writing to the tag. Of course Im testing in with value changed from 0 to 1. Tried examples from manuals/forum and in general every example with IF failed to write to the tag. Any ideas ?

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):

```
pathA = system.tag.read("[.]PLC_Path_A").value
pathB = system.tag.read("[.]PLC_Path_B").value

cur = currentValue
prv = previousValue

if cur.value is True:    
system.tag.writeBlocking("[.]PLC_Path_Ref", pathA )

```

---

<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 11, 2023, 3:19pm UTC](https://forum.inductiveautomation.com/t/if-condition-in-tag-change-script-issue/76196/2 "2023-07-11T15:19:31Z")

</div>

> [@Mariusz\_Balon](#):
>
> ```auto
> if cur.value is True:    
> system.tag.writeBlocking("[.]PLC_Path_Ref", pathA )
> 
> ```

This should be:

```auto
if cur.value:
	system.tag.writeBlocking(["[.]PLC_Path_Ref"], [pathA])

```

Notes:

- Don't compare booleans to `True` or `False`. Just use them, perhaps with `not`.

- Python/Jython requires indentation to delimit blocks of code.

- `.writeBlocking()` is designed to handle multiple writes at once, and therefore needs _lists_ of paths and values.

---

<div class="post-metadata">

**Author:** ![Mariusz\_Balon](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@Mariusz\_Balon](https://forum.inductiveautomation.com/u/Mariusz_Balon)\
**Post date:** [July 11, 2023, 3:25pm UTC](https://forum.inductiveautomation.com/t/if-condition-in-tag-change-script-issue/76196/3 "2023-07-11T15:25:30Z")

</div>

Sorted. Many 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:** [July 11, 2023, 4:03pm UTC](https://forum.inductiveautomation.com/t/if-condition-in-tag-change-script-issue/76196/4 "2023-07-11T16:03:51Z")

</div>

Just wanted to add this, since Phil didn't mention it, but `system.tag.read()` has been deprecated and you should be using `system.tag.readBlocking()` which is designed to read multiple paths at once and so accepts a list of tag paths and returns a list of qualified values.

I'm not sure why you're reading pathB in this script since you don't show it being used but if you did need both values it should be read like this.

```auto
tagA,tagB = system.tag.readBlocking(['[.]PLC_Path_A','[.]PLC_Path_B'])

#Or
#tagA = system.tag.readBlocking(['[.]PLC_Path_A','[.]PLC_Path_B'])[0].value

if currentValue.value:
     system.tag.writeBlocking(['[.]PLC_Path_Ref'],[tagA.value])

```

I'm also surprised that @pturmel didn't caution you about running blocking scripts in tag value change scripts. Do a search for the pitfalls, particularly if this UDT will have many instances.

---

<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 11, 2023, 4:36pm UTC](https://forum.inductiveautomation.com/t/if-condition-in-tag-change-script-issue/76196/5 "2023-07-11T16:36:04Z")

</div>

> [@lrose](#):
>
> surprised that pturmel didn't caution you about running blocking scripts in tag value change scripts

Huh. The leading `def` isn't in the code block and rest is not indented--threw me off. +1

---

<div class="post-metadata">

**Author:** ![Mariusz\_Balon](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@Mariusz\_Balon](https://forum.inductiveautomation.com/u/Mariusz_Balon)\
**Post date:** [July 12, 2023, 9:21am UTC](https://forum.inductiveautomation.com/t/if-condition-in-tag-change-script-issue/76196/6 "2023-07-12T09:21:52Z")

</div>

The intention of this scripting is to replace OPCItempath in the UDT instances for redundant S7400 comms based on Master/Slave status PLC tag (bool). This tag only change and execute UDT scripts once in year, or even less often. Should I be aware of any Ignition performance issues etc.. ?

Tag Change scripting looks bit neater solution comparing to gateway script.

---

<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 12, 2023, 3:26pm UTC](https://forum.inductiveautomation.com/t/if-condition-in-tag-change-script-issue/76196/7 "2023-07-12T15:26:50Z")

</div>

> [@Mariusz\_Balon](#):
>
> This tag only change and execute UDT scripts once in year, or even less often

I wouldn't bother with a script at all then, I would just create a UDT parameter and change it manually if it needed it. Oh well. Either way, I guarantee that it runs more than that. So while it may seem harmless to you, you should definitely be aware of the rope you're walking on. The thread pool available for tag scripts is very small, and if you're not careful you'll have random failures due to chewing up that pool. It will be very difficult to find when you notice it (I have been there, and done that, not fun.)

---

<div class="post-metadata">

**Author:** ![Mariusz\_Balon](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@Mariusz\_Balon](https://forum.inductiveautomation.com/u/Mariusz_Balon)\
**Post date:** [July 12, 2023, 5:37pm UTC](https://forum.inductiveautomation.com/t/if-condition-in-tag-change-script-issue/76196/8 "2023-07-12T17:37:21Z")

</div>

Unfortunately manual change is not an option i.e. client would not accept it. Needs to be automated somehow.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [July 12, 2023, 6:00pm UTC](https://forum.inductiveautomation.com/t/if-condition-in-tag-change-script-issue/76196/9 "2023-07-12T18:00:17Z")

</div>

I think this is a good example where the wrong question was asked. It seems this is more of a redundancy question than anything else.

If that's correct take a look at this recent post, perhaps it will be of some assistance.

> [@Indirect OpcItemPath](https://forum.inductiveautomation.com/t/indirect-opcitempath/74957/10):
>
> A bit about my redundancy setup - the PLCs I’m communicating to have redundant modbus communication cards. Each comms card has its own IP address, but in the back end the 2 cards are reading and writing to the same PLC memory points. Some other SCADA systems I’ve used have support for this built in - when setting up the comms driver, you can tick the box for redundancy, and add the second IP address. The SCADA system then gracefully fails over between the primary and secondary channels based on…

---

<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 12, 2023, 6:18pm UTC](https://forum.inductiveautomation.com/t/if-condition-in-tag-change-script-issue/76196/10 "2023-07-12T18:18:36Z")

</div>

Too bad I can't help with Siemens....

{ /shudder }
