# Script as a label

**URL:** <https://forum.inductiveautomation.com/t/script-as-a-label/66073>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [November 3, 2022, 2:36pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073 "2022-11-03T14:36:18Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [November 3, 2022, 2:36pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073/1 "2022-11-03T14:36:18Z")

</div>

I am looking at having a tables previousValue compare to the currentValue then launch a popup. What would be the best practice to do this?

So far I have thought about this, executing off a change script on the table:

```auto
	if self.props.data.previousValue < self.props.data.currentValue:
		system.perspective.openPopup('','Popup/New Message')

```

---

<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:** [November 3, 2022, 2:53pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073/2 "2022-11-03T14:53:11Z")

</div>

What does it mean for a `DataSet` to be less than another `DataSet`?

I would think it would need to be something like:

```auto
if not currentValue.value.equals(previousValue.value):
    system.perspective.openPopup('','Popup/New Message')

```

Since datasets are immutable, I would think this would be true any time the binding updates, even if the actual data hasn't changed? Which maybe isn't what you want?

@paul-griffith Have some insight?

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [November 3, 2022, 2:55pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073/3 "2022-11-03T14:55:09Z")

</div>

I must have misunderstood the terms then, I thought for whatever reason it knew what its previousValue was

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [November 3, 2022, 3:05pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073/4 "2022-11-03T15:05:19Z")

</div>

I changed my script like this:

```auto
if previousValue < currentValue:
	system.perspective.openPopup('','Popup/New Message')

```

It seems to be launching mulitple popups. What would cause this?

I do want the popup to happen eveytime the data in the dataset updates.

---

<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:** [November 3, 2022, 3:13pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073/5 "2022-11-03T15:13:40Z")

</div>

Well, first. previousValue and currentValue are Qualified values, so to get to the actual dataset, you would need `previousValue.value` as I have shown.

Second, I don't think that `<` is a valid comparison for Datasets. It's not like comparing integers.

---

<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:** [November 3, 2022, 3:14pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073/6 "2022-11-03T15:14:31Z")

</div>

The property change event _itself_ does change de-duplication, except for the fact that datasets are compared by identity, so will _always_ be different, even if the data within is the same. Depending on what changes you expect to happen to your dataset, perhaps you could compare the row count between currentValue and previousValue?

---

<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:** [November 3, 2022, 3:16pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073/7 "2022-11-03T15:16:23Z")

</div>

As a tangent, I considered adding `system.dataset.valuesEqual(dataset, dataset)`, `system.dataset.columnsEqual(dataset, dataset)` to Ignition Extensions; might still do something like that.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [November 3, 2022, 3:24pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073/8 "2022-11-03T15:24:19Z")

</div>

Thats my fault I did forget to add the len() to get row count.

```auto
	curVal = len(currentValue.value)
	preVal = len(previousValue.value)

	if curVal != preVal:
		system.perspective.openPopup('','Popup/New Message')`

```

When I do this I get an error at line 3, which is the len(previousValue.value), it states:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/e/9eeb434f24947c6d6dc81dd1e90cb182b9ad2a97.png)

---

<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:** [November 3, 2022, 3:28pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073/9 "2022-11-03T15:28:49Z")

</div>

If you want to compare the row count, then use the rowCount property. On initial change the previous value can be `None` so you need to check for that.

```auto
if previousValue and currentValue.value.rowCount != previousValue.value.rowCount:
    system.perspective.openPopup('','Popup/New Message')

```

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [November 3, 2022, 4:06pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073/10 "2022-11-03T16:06:36Z")

</div>

> [@lrose](#):
>
> `previousValue.value`

oh ok I thought you had to use len()

I am getting this error:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/3/53c285b41902efaea6beb0c80b504013df04815b.png)

---

<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:** [November 3, 2022, 4:07pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073/11 "2022-11-03T16:07:57Z")

</div>

Modifying @lrose' last snippet:

```auto
if previousValue is not None and currentValue.value.rowCount != previousValue.value.rowCount:
    system.perspective.openPopup('','Popup/New Message')

```

---

<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:** [November 3, 2022, 4:09pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073/12 "2022-11-03T16:09:00Z")

</div>

Thanks, I always forget it's the whole QualifiedValue Object that is None, not just the value.

Original script edited.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [November 3, 2022, 4:15pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073/13 "2022-11-03T16:15:20Z")

</div>

the script runs. I am getting multiple popups though, instead of just one.

Could it be that this table is part of a larger table that is being edited by a named query parameter? I have included the binding for that table:

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

the table filter is hte "0000100147" number above the props window

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [November 3, 2022, 5:26pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073/14 "2022-11-03T17:26:38Z")

</div>

So I assume I am geeting multiple popups due it being on a change script and thats executing the script all the time. Anyway to limit that?

---

<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:** [November 3, 2022, 5:56pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073/15 "2022-11-03T17:56:18Z")

</div>

What do you want to happen when the table is updated while there's already a popup opened ?  
Replace the old one, or prevent the new one from popping up ?  
First case, assign a fixed id to your popup, and call the close popup function with this id before opening a new one.  
Second case, you'll need to keep track of whether or not a popup is already opened, and prevent any new one to pop before it's closed.

But if they keep popping up, you'll run into another issue: you'll always have one opened, has every time you close one, another one will pop soon. You might need to rethink the trigger.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [November 3, 2022, 6:27pm UTC](https://forum.inductiveautomation.com/t/script-as-a-label/66073/16 "2022-11-03T18:27:37Z")

</div>

I would like to be able to compare table1.previousValue to table1.currentValue as session or component custom props, but Im not sure how to write the expression for each one of those. I do know that if I did len(table1.props.data) would give me current value but not sure how get a previous row count. Then have that comparison run a openPopup script.
