Attempting to remove element from Flex Repeater

I am trying to set up a button on an embedded view that I have in a template repeater, that will then do an array.remove() on the instances property of the flex repeater.
the error I am getting look like it can’t match up the element params, with the params in the view.

Event Script on the button in the embedded view

system.perspective.sendMessage('removeListItem', {'listItem':self.view.params})

Message handler script on the flex repeater

from com.inductiveautomation.ignition.common import TypeUtilities
listItem = TypeUtilities.pyToGson(payload['listItem'])
instances = TypeUtilities.pyToGson(self.props.instances)
instances.remove(listItem)

The error I am getting

com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
  File "<function:onMessageReceived>", line 5, in onMessageReceived
ValueError: array.remove({"alarm":false,"analogParams":{"formatString":"#,##0.#","tagPath":"[CarefreeSCADA]Customers/Demo/reservoir/Reads/Well_Flow","name":"Well Flow","engUnits":"gpm"},"analyticsParams":{"calcDuration":24,"dataAggregation":"Average","enabled":false},"instancePosition":{},"instanceStyle":{"classes":""},"popup":true}): {"alarm":false,"analogParams":{"formatString":"#,##0.#","tagPath":"[CarefreeSCADA]Customers/Demo/reservoir/Reads/Well_Flow","name":"Well Flow","engUnits":"gpm"},"analyticsParams":{"calcDuration":24,"dataAggregation":"Average","enabled":false},"instancePosition":{},"instanceStyle":{"classes":""},"popup":true} not found in array

	caused by org.python.core.PyException
Traceback (most recent call last):
  File "<function:onMessageReceived>", line 5, in onMessageReceived
ValueError: array.remove({"alarm":false,"analogParams":{"formatString":"#,##0.#","tagPath":"[CarefreeSCADA]Customers/Demo/reservoir/Reads/Well_Flow","name":"Well Flow","engUnits":"gpm"},"analyticsParams":{"calcDuration":24,"dataAggregation":"Average","enabled":false},"instancePosition":{},"instanceStyle":{"classes":""},"popup":true}): {"alarm":false,"analogParams":{"formatString":"#,##0.#","tagPath":"[CarefreeSCADA]Customers/Demo/reservoir/Reads/Well_Flow","name":"Well Flow","engUnits":"gpm"},"analyticsParams":{"calcDuration":24,"dataAggregation":"Average","enabled":false},"instancePosition":{},"instanceStyle":{"classes":""},"popup":true} not found in array


Ignition v8.1.0-rc1 (b2020091420)
Java: Azul Systems, Inc. 11.0.7

I would bet it’s because the instances array is an array of ObjectWrapper() objects, not technically an array of dictionaries.you could try to not convert your self.view.params to json for the message handler?

Or depending on how large your list is, you could just iterate with enumerate to compare each object to the dictionary, find the index and pop it that way. Not optimal, but possible

I’m going to side with @kgamble here: when I examine the types being compared, I see that the instances are of type array.array, while the converted payload is of type com.inductiveautomation.ignition.common.script.adapters.PyJsonObjectAdapter.

Of course, all of this is far more complex than it needs to be.

  1. You’ve configured the instanced View’s params to include properties it doesn’t need (increases load on running session, because all of those values are stored in the browser for each instance).
  2. You’re trying to take a direct-comparison removal to remove the EXACT match (which makes sense in some ways), when you could just as easily provide a unique identifier for each instance. Is the tagPath unique? If so, just specify to remove an instance where the tagPath matches the tagPath in the payload.
2 Likes

Yeah the tagPath should be unique,
So the solution would be as @kgamble said and use enumerate to go through the instance list, find the index where it matches tagPath then pop or delete from there?
Thanks all, I’ll give it a try this evening!

1 Like

Was able to test it out last night using enumerate and got it working! I set up an id param on the embedded view that gets a generated uuid whenever its created to be 100% sure I’m removing the right one. Thanks for your assistance! @kgamble @cmallonee

2 Likes