Datasets arriving to Component Message Handlers as 'PropertyTreeScriptWrapper.ArrayWrapper.html'

I've been struggling for a few days with a problem that started when I tried to convert a dataset to a pydataset.

I have a dataset that is generated by a named query on a custom component.
On this component, I have no trouble calling toPyDataset
On a separate custom property, I grab the type of this dataset, and print it out.

I then pass the dataset to a secondary component as a parameter. (My primary is a Map, the secondary is a view that's tied in with the customControl ~'embedded view'~ prop of the Map, if you're curious)

this secondary view gets this lovely data passed as a parameter.
On a separate custom property on the view, I grab the type of this dataset parameter, and print it out.

Lastly, I have a message handler which reacts to a different set of changing data. My ultimate goal is to be able to read data out of the secondary view's dataset parameter and print out data.
Inside of the message handler script I grab the type of this dataset from the secondary view, and print it out.

And here's the fantastic result of all three of these print statements, once I navigate to this page!

Primary : <type 'com.inductiveautomation.ignition.common.JsonDataset'>
Primary : <type 'com.inductiveautomation.ignition.gateway.datasource.BasicStreamingDataset'>
Secondary: <type 'com.inductiveautomation.ignition.common.JsonDataset'>
Secondary: <type 'com.inductiveautomation.perspective.gateway.script.JsonifiableArrayList'>
in Message Handler: <type 'com.inductiveautomation.perspective.gateway.script.PropertyTreeScriptWrapper$ArrayWrapper'>

Isn't that grand! three different dataset types. BasicStreamingDataset, JsonifiableArrayList, and. PropertyTreeScriptWrapper$ArrayWrapper'.
the first two i've been able to manipulate. the last one? completely unsuccessful.

Tried looking at the doc for ArrayWrapper and i'm... i'm lost. should I even be able to iterate over it?

getPyDataset breaks without returning anything. ditto with jsonDecode, .items(). I really don't wanna have to toString it and do some funky jsonEncode stuff unless I have to.
Any direction or support would help. the existing threads on reading an object wrapper seemed to be on the right track but didn't include any code I could use and used a clunky method. like victordcq said, 'You should not have to en/decode it to json'.
code for the curious.

def onMessageRecieved(self, payload):
  NFSM = self.view.params.Nav_Filter_Sites_Map
  system.perspective.print('in Message Handler: ' + str(type(NFSM)))

with gratitude,
-AM

Can you break down the exact problem you have and what you're trying to solve?

Primary : <type 'com.inductiveautomation.ignition.gateway.datasource.BasicStreamingDataset'>
Secondary: <type 'com.inductiveautomation.ignition.common.JsonDataset'>

Only these first two types are actually Dataset types.

Secondary: <type 'com.inductiveautomation.perspective.gateway.script.JsonifiableArrayList'>
in Message Handler: <type 'com.inductiveautomation.perspective.gateway.script.PropertyTreeScriptWrapper$ArrayWrapper'>

These two types are both, essentially, imitations of a Python list, just like PyDataset is. That list may contain "row-like" objects, or it may not - the type of the outer list won't tell you.

There's more and less good rational explanations for why all these different types are being surfaced to you, but the generally better guiding principle is to just not care, and treat things as what they pretend to be.

Ok! hey thank you for giving me hope! so the goal I had was to be able to iterate over the PropertyTreeScriptWrapper$ArrayWrapper' that the message handler picks up from self.view.params.Nav_Filter_Sites_Map there's some data inside of that dataset that i'd like to use.
since toPyDataset doesn't work, my guess is because there's some sort of wrapper around the data in that object? But yeah, essentially how do I get to those delicious morsels of dataset data.
the drawback I kept running into with testing this too was not getting any console data from system.perspective.print after attempting a 'toPyDataset', I assume my scripting just failed in a less-visible sort of way

When dealing with an ArrayWrapper, just treat it as a regular list, e.g:

for i, site in enumerate(self.view.params.Nav_Filter_Sites_Map):
	system.perspective.print("Index %s" % i)
	system.perspective.print(str(type(site))
	system.perspective.print(repr(site))

2 Likes

Probably something like:

for row in self.view.params.Nav_Filter_Sites_Map:
    print row['ColumnName']

You'll find that your ArrayWrapper is an Array of ObjectWrappers, which looks almost exactly like a List of Dictionaries.

Of course, you could set your Named Query Binding's return format to dataset and pass around an actual Dataset object too.

Yes, it was never reaching the print call.

2 Likes

Thank you thoroughly! Both of your solutions provide that sweet, delectable, data access that I needed!

#PGriffith
	for i, site in enumerate(self.view.params.Nav_Filter_Sites_Map):
		system.perspective.print("Index %s" % i)
		system.perspective.print(str(type(site)))
		system.perspective.print(repr(site))
#lrose		
	for row in self.view.params.Nav_Filter_Sites_Map:
		system.perspective.print( row['Latitude'])

I'll be on my merry way then.

@PGriffith, thanks for helping get me un-stuck! I'm going to go learn about 'repr' now, it looks handy!

And thank you too @lrose! Great knowing another Illinois graduate is on here. I-L-L !

-AM

Well, I didn’t actually graduate from there, instead graduated from SIUE, but I grew up in IL and have been a life long fan, so I-N-I !

1 Like

The work continues!
This was solved, but there are lots of wrappers in use across perspective if you're reading this thread and want more info, there's a fantastic couple of script tools here that were cooked up by some talented members of the community.
Good luck; have fun!