# BUG?: Strange behaviour while comparing two strings in component event script

**URL:** <https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877>\
**Category:** Ignition\
**Tags:** scripting, vision, ignition81\
**Created:** [May 3, 2024, 8:35am UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877 "2024-05-03T08:35:42Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Om33](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Om33](https://forum.inductiveautomation.com/u/Om33)\
**Post date:** [May 6, 2024, 7:20am UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/21 "2024-05-06T07:20:16Z")

</div>

> [@Om33](#):
>
> `tagPaths.getColumnAsList(0)`

this is always a constant list, thus the only thing that can change here is `event.source.text`

---

<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:** [May 6, 2024, 7:29am UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/22 "2024-05-06T07:29:56Z")

</div>

Try putting it in a library script, so the actual event script only grabs the parameters and passes them to the function. Isolate things to reduce unexpected behavior:

library script:

```python
def func(user_input, tag_path, table_name, start_time, end_time):
	id_list = system.tag.readBlocking(tag_path)[0].value.getColumnAsList(0)
	
	if user_input not in id_list:
		return False, None, None

	query_params = {
		'tableName': table_name,
		'start': start_time,
		'end': end_time,
		'user_input': user_input
	}
	count_result = system.db.runNamedQuery("countStop", query_params)
	duration_result = system.db.runNamedQuery("calculateDurationStop", query_params)

	return True, count_result, duration_result

```

event script:

```python
if event.keyCode == event.VK_ENTER:
	folderPath = event.source.parent.dataPath

	flowVar, count_result, duration_result = func(
		user_input = event.source.text,
		tag_path = "{}/AlarmData/alarmList".format(folderPath),
		table_name = "Alarm_{}".format(folderPath.rsplit("/", 1)[1])
		start_time = system.gui.getWindow("Standard Window/Alarms").getRootContainer().getComponent("Cal_Start").date,
		end_time = system.gui.getWindow("Standard Window/Alarms").getRootContainer().getComponent("Cal_End").date
	)

```

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [May 6, 2024, 8:39am UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/23 "2024-05-06T08:39:20Z")

</div>

So you are saying you have a printout from a text value that is not inside the string list yet still returned true? on a script that only runs once.  
if so plz provide a screenshot of this and give us this list and value to see if its repeatable

---

<div class="post-metadata">

**Author:** ![Om33](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Om33](https://forum.inductiveautomation.com/u/Om33)\
**Post date:** [May 6, 2024, 9:46am UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/24 "2024-05-06T09:46:24Z")

</div>

> [@Om33](#):
>
> ```python
> event.source.parent.getComponent("lblnumberStops").text=str(count_result)
> event.source.parent.getComponent("lbltotalDur").text=shared.Func_Dataset.format_duration(duration_result)
> 
> ```

I found the problem. you were right, it definitely has something to do with the assignment. I have commented all code lines and then removed the comments line after line and the problem occurs exactly when I add those two lines.

But how to avoid this assigment then? Is there an embedded function to display a value using a label component?

---

<div class="post-metadata">

**Author:** ![Om33](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Om33](https://forum.inductiveautomation.com/u/Om33)\
**Post date:** [May 6, 2024, 9:47am UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/25 "2024-05-06T09:47:43Z")

</div>

I can not publish the exact values, but I think this should be repeatable with random values too

---

<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:** [May 6, 2024, 10:30am UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/26 "2024-05-06T10:30:50Z")

</div>

This doesn't make much sense:  
Those lines are IN the if scope, there's no way they can effect whether the if gets executed or not.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [May 6, 2024, 10:41am UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/27 "2024-05-06T10:41:21Z")

</div>

No i cant, i can not replicate the behaviour you are describing.  
If find something that works on static values in one script (without going to tags so everyone can run it), please share

---

<div class="post-metadata">

**Author:** ![Om33](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Om33](https://forum.inductiveautomation.com/u/Om33)\
**Post date:** [May 6, 2024, 11:27am UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/28 "2024-05-06T11:27:22Z")

</div>

You are right, I can also not replicate the error with a static list in the script. But how should the Tag be a problem? It is just a memory dataset and there is no write-operation on it anywhere.

---

<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:** [May 6, 2024, 12:10pm UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/29 "2024-05-06T12:10:06Z")

</div>

Let's take a few steps back and try to reduce the example size, maybe we can pinpoint where exactly things are going wrong.

Add a button and use it to trigger a script like this:

```python
ids_list = system.tag.readBlocking(["path to one of your dataset tags"])[0].value.getColumnAsList(0)

print ('some_invalid_input' in ids_list)
print ('some_valid_input' in ids_list)

```

If this shows the correct behavior, add things in little increments:

- get the input from a component instead of using a literal
- put the script on a key event instead of a button
- etc.

If you find a situation that reproduces the error, start examining everything very carefully.

---

<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:** [May 6, 2024, 12:39pm UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/30 "2024-05-06T12:39:11Z")

</div>

When you assign to a component property, and that property has its own change monitoring, the side effects will start immediately-- **recursively** --before the current script ends.

---

<div class="post-metadata">

**Author:** ![Om33](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Om33](https://forum.inductiveautomation.com/u/Om33)\
**Post date:** [May 6, 2024, 12:54pm UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/31 "2024-05-06T12:54:48Z")

</div>

I tried it. It works when triggered with a button. And it's now also working within the keyPressed event. I think, I will let this functionality by side first because it is not reliable for the moment.

Thank you

---

<div class="post-metadata">

**Author:** ![Om33](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Om33](https://forum.inductiveautomation.com/u/Om33)\
**Post date:** [May 6, 2024, 12:55pm UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/32 "2024-05-06T12:55:59Z")

</div>

Okay thank you, I can not avoid assigning, since I want to display a value with a label component.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [May 6, 2024, 12:56pm UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/33 "2024-05-06T12:56:30Z")

</div>

i think you should not just let this go to the side, there is clearly something wrong with the way this is getting handled, you might repeat a similar mistake somewhere else

---

<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:** [May 6, 2024, 12:56pm UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/34 "2024-05-06T12:56:44Z")

</div>

Then do that assignment **last** , outside any loop.

(Is something binding to that label's text? That would feed back into a change that triggers your original code?)

---

<div class="post-metadata">

**Author:** ![Om33](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Om33](https://forum.inductiveautomation.com/u/Om33)\
**Post date:** [May 6, 2024, 1:00pm UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/35 "2024-05-06T13:00:58Z")

</div>

I'm working with ignition in Trial Mode , maybe the behaviour will be different in the production mode?

---

<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:** [May 6, 2024, 1:01pm UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/36 "2024-05-06T13:01:54Z")

</div>

No, trial mode and production mode are identical for Ignition itself. (3rd party modules might have differences, but not likely.)

---

<div class="post-metadata">

**Author:** ![Om33](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Om33](https://forum.inductiveautomation.com/u/Om33)\
**Post date:** [May 6, 2024, 1:02pm UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/37 "2024-05-06T13:02:14Z")

</div>

No there is no binding, but there are multiple write-operation on the label at different places within the project

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [May 6, 2024, 1:04pm UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/38 "2024-05-06T13:04:03Z")

</div>

> [@Om33](#):
>
> multiple write-operation on the label

well that is really weird, you dont use a label to store date, you should use a tag, and write stuff to the tag and let the label read the tag.  
For things that can change per user, use a client tag, so everyone can filter on their own

---

<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:** [May 6, 2024, 1:24pm UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/39 "2024-05-06T13:24:57Z")

</div>

> [@victordcq](#):
>
> you should use a tag,

Might want to use a custom property or top level script variable, depending on the scope that the data needs to be persistent in.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [May 6, 2024, 3:02pm UTC](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877/40 "2024-05-06T15:02:54Z")

</div>

> [@Om33](#):
>
> at different places within the project

this sounds like a client tag to me, its a vision project so this should be fine no? (i dont really work with vision)

[Previous page](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877.md?page=1)

[Next page](https://forum.inductiveautomation.com/t/bug-strange-behaviour-while-comparing-two-strings-in-component-event-script/89877.md?page=3)
