Script as a label

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:

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

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

I would think it would need to be something like:

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?

@PGriffith Have some insight?

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

I changed my script like this:

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.

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.

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?

1 Like

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.

1 Like

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

	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

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.

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

oh ok I thought you had to use len()

I am getting this error:

Modifying @lrose' last snippet:

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

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

Original script edited.

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:

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

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?

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.

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.