# \[Question\] Looping through array parameter in script

**URL:** <https://forum.inductiveautomation.com/t/question-looping-through-array-parameter-in-script/24743>\
**Category:** Ignition Early Access\
**Created:** [May 7, 2019, 12:45pm UTC](https://forum.inductiveautomation.com/t/question-looping-through-array-parameter-in-script/24743 "2019-05-07T12:45:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [May 7, 2019, 12:45pm UTC](https://forum.inductiveautomation.com/t/question-looping-through-array-parameter-in-script/24743/1 "2019-05-07T12:45:58Z")

</div>

I have a named query returning a dataset that I am using as a parameter in a popup window. I can pull values out of the dataset, and do a transform to get the individual values within the view, but I am having issues when I try and get the individual values out using my event script for when the popup is closing.

Here is my base script for now:

```auto
	data = self.getSibling("EmbeddedView").props.params.datasource
	newOrEdit = self.view.params.newRecipe
	PN = self.view.params.PN
	Rev = system.db.runNamedQuery('AeroDef', 'GetMaxRevision', {"PN":PN}).getValueAt(0,0)+1
	log=system.util.getLogger("Garrett Logger")
	log.warn("%s"%data)
	i=0
	ribNo1 = data[0][2]
	dispRate1 = data[0][3]
	dispSpeed1 = data[0][4]
	beadH1 = data[0][5]
	beadW1 = data[0][6]
	log.warn("%s"%ribNo1)

```

If I run it as it is there, it throws an error saying the following.

```auto
Caused by: org.python.core.PyException: Traceback (most recent call last): File "", line 10, in runAction TypeError: 'com.inductiveautomation.perspective.gateway.script.PropertyTreeScriptWrapper$MapWrapper' object is unsubscriptable

```

The data type as an array, so I tried pop, which will give me the row, but it returns as an ‘com.inductiveautomation.perspective.common.Immutab’ and I can’t get any data out of that easily it seems.

Any ideas on what the best way to approach this is?

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [May 7, 2019, 12:47pm UTC](https://forum.inductiveautomation.com/t/question-looping-through-array-parameter-in-script/24743/2 "2019-05-07T12:47:21Z")

</div>

This is what the data variable is returning when I print it to the logs, though I added some linebreaks to make it readable

```auto
array(java.lang.Object, [QV[{BeadHeight=[2, Good, Wed Dec 31 19:00:00 EST 1969 (191)], Revision=[4, Good, Wed Dec 31 19:00:00 EST 1969 (191)], PartNum=[PN5 , Good, Wed Dec 31 19:00:00 EST 1969 (191)], BeadWidth=[2.2, Good, Wed Dec 31 19:00:00 EST 1969 (191)], RibNum=[1, Good, Wed Dec 31 19:00:00 EST 1969 (191)], DispenseRate=[1.23, Good, Wed Dec 31 19:00:00 EST 1969 (191)], DispenseSpeed=[1.25, Good, Wed Dec 31 19:00:00 EST 1969 (191)]}, Good, Wed Dec 31 19:00:00 EST 1969], 
QV[{BeadHeight=[2.1, Good, Wed Dec 31 19:00:00 EST 1969 (192)], Revision=[4, Good, Wed Dec 31 19:00:00 EST 1969 (191)], PartNum=[PN5 , Good, Wed Dec 31 19:00:00 EST 1969 (191)], BeadWidth=[2.5, Good, Wed Dec 31 19:00:00 EST 1969 (192)], RibNum=[2, Good, Wed Dec 31 19:00:00 EST 1969 (191)], DispenseRate=[1.35, Good, Wed Dec 31 19:00:00 EST 1969 (192)], DispenseSpeed=[1.35, Good, Wed Dec 31 19:00:00 EST 1969 (192)]}, Good, Wed Dec 31 19:00:00 EST 1969], 
QV[{BeadHeight=[4.2, Good, Wed Dec 31 19:00:00 EST 1969 (192)], Revision=[4, Good, Wed Dec 31 19:00:00 EST 1969 (192)], PartNum=[PN5 , Good, Wed Dec 31 19:00:00 EST 1969 (192)], BeadWidth=[1.2, Good, Wed Dec 31 19:00:00 EST 1969 (192)], RibNum=[3, Good, Wed Dec 31 19:00:00 EST 1969 (192)], DispenseRate=[3.12, Good, Wed Dec 31 19:00:00 EST 1969 (192)], DispenseSpeed=[1.4, Good, Wed Dec 31 19:00:00 EST 1969 (192)]}, Good, Wed Dec 31 19:00:00 EST 1969], 
QV[{BeadHeight=[2, Good, Wed Dec 31 19:00:00 EST 1969 (192)], Revision=[4, Good, Wed Dec 31 19:00:00 EST 1969 (192)], PartNum=[PN5 , Good, Wed Dec 31 19:00:00 EST 1969 (192)], BeadWidth=[2.1, Good, Wed Dec 31 19:00:00 EST 1969 (192)], RibNum=[4, Good, Wed Dec 31 19:00:00 EST 1969 (192)], DispenseRate=[2.2, Good, Wed Dec 31 19:00:00 EST 1969 (192)], DispenseSpeed=[2.1, Good, Wed Dec 31 19:00:00 EST 1969 (192)]}, Good, Wed Dec 31 19:00:00 EST 1969], 
QV[{BeadHeight=[2.1, Good, Wed Dec 31 19:00:00 EST 1969 (192)], Revision=[4, Good, Wed Dec 31 19:00:00 EST 1969 (192)], PartNum=[PN5 , Good, Wed Dec 31 19:00:00 EST 1969 (192)], BeadWidth=[1.9, Good, Wed Dec 31 19:00:00 EST 1969 (192)], RibNum=[5, Good, Wed Dec 31 19:00:00 EST 1969 (192)], DispenseRate=[1.4, Good, Wed Dec 31 19:00:00 EST 1969 (192)], DispenseSpeed=[1.5, Good, Wed Dec 31 19:00:00 EST 1969 (192)]}, Good, Wed Dec 31 19:00:00 EST 1969]])

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 7, 2019, 12:55pm UTC](https://forum.inductiveautomation.com/t/question-looping-through-array-parameter-in-script/24743/3 "2019-05-07T12:55:58Z")

</div>

Can you try something like:

```auto
dataList = data.items()

```

and then print the `dataList` and see what you get?

Also, do you mean to be accessing the `data` variable rather than the results of your query?

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [May 7, 2019, 12:59pm UTC](https://forum.inductiveautomation.com/t/question-looping-through-array-parameter-in-script/24743/4 "2019-05-07T12:59:24Z")

</div>

```auto
in runAction AttributeError: 'array.array' object has no attribute 'items'

```

Yes data variable is what I am trying to access. I mentioned the name query since it is populated with the data from that when the window loads, but I guess it isn’t really important to troubleshooting.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 7, 2019, 1:08pm UTC](https://forum.inductiveautomation.com/t/question-looping-through-array-parameter-in-script/24743/5 "2019-05-07T13:08:18Z")

</div>

Try calling `data[0].items()` instead.

It seems you’re getting an array of these property tree MapWrapper objects…

I think you’re meant to access it like JSON, it’s not a dataset.

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [May 7, 2019, 1:11pm UTC](https://forum.inductiveautomation.com/t/question-looping-through-array-parameter-in-script/24743/6 "2019-05-07T13:11:46Z")

</div>

Still not finding that attribute.

Is there an way to loop through the values in JSON? The parameter shows as dataset in the property editor, so that’s where I started, but as long as I can extract the data for the database, I’m fine with going another route.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 7, 2019, 1:13pm UTC](https://forum.inductiveautomation.com/t/question-looping-through-array-parameter-in-script/24743/7 "2019-05-07T13:13:55Z")

</div>

I’ll have to let someone more familiar with Perspective come in and figure this out, I’m still not sure what that object is. The “QV” in it might mean it’s an array of QualifiedValues, and each of the values in the QV is a MapWrapper object.

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [May 7, 2019, 1:17pm UTC](https://forum.inductiveautomation.com/t/question-looping-through-array-parameter-in-script/24743/8 "2019-05-07T13:17:15Z")

</div>

Glad we aren’t the only ones a bit stumped. It seems to be returning a PyArray when I pull it into the data variable, but we can’t get much further down into the array to get to the actual values.

---

<div class="post-metadata">

**Author:** ![rbanaszak](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rbanaszak/32/6929_2.png) [@rbanaszak](https://forum.inductiveautomation.com/u/rbanaszak)\
**Post date:** [May 7, 2019, 1:38pm UTC](https://forum.inductiveautomation.com/t/question-looping-through-array-parameter-in-script/24743/9 "2019-05-07T13:38:25Z")

</div>

Figured it out, given the tree MapWrapper object, we were able to call the specific attributes as defined by the original query.

edit for clarification: image shows how datasource is displayed in property editor.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/7bc8bd4cd55dd6f26d43d01fee108e7b4fecba49.png)

```auto
data = self.getSibling("EmbeddedView").props.params.datasource
length = len(data)
for i in range(len(data)):
	ds = data[i]
	rev= ds.Revision
	rib = ds.RibNum
	disRate = ds.DispenseRate
	disSpeed = ds.DispenseSpeed
	bh = ds.BeadHeight
	bw = ds.BeadWidth
```
