# Pass pyrow to sub view

**URL:** <https://forum.inductiveautomation.com/t/pass-pyrow-to-sub-view/70823>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [March 9, 2023, 1:03pm UTC](https://forum.inductiveautomation.com/t/pass-pyrow-to-sub-view/70823 "2023-03-09T13:03:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AGOSTINO\_SCLAUZERO](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@AGOSTINO\_SCLAUZERO](https://forum.inductiveautomation.com/u/AGOSTINO_SCLAUZERO)\
**Post date:** [March 9, 2023, 1:03pm UTC](https://forum.inductiveautomation.com/t/pass-pyrow-to-sub-view/70823/1 "2023-03-09T13:03:59Z")

</div>

I've got a master-detail view.  
The master loads a resultset from a database.  
This resultset is used to generate the instances property of a FlexRepeater that repeats a subview for each row.  
In a first implementation I passed to the subview the key of that row; the view used that key to issue a query for that single row and get its own resultset that I kept in a custom property of the view and used to populate TextFields values via binding like

```
getValueAt(0, "FIELDNAME")

```

This worked but now I would like to explore the possibility of passing directly the row-data from the master, without having each instance of the view, that is each row to reload it's own data.

I bound the instances property of the FlexRepeater to a field with my record primary key (invoice's id) and I used the following binding script:

```
instances = []
for r in system.db.runPrepQuery("SELECT * FROM INVOICEROWS WHERE INVOICEID=?", [value]):		
	print str(type(r))
	instances.append({"row": r})
return instances  

```

My view obviously has a row parameter that should hold a representation of my row data.  
Here I noticed that the type of r is `PyRow`.  
If i check the type on the view side, that is the type of row parameter I see: `JsonifiableArrayList`.  
The problem here is that in this process the column names get lost, so then I can only access values by index and not by column name anymore, and this is something that I would like to avoid.  
(I've read somewhere that when python types are saved to properties they get 'stringified', I don't know if this is the case since I don't actally get a string but still a list.).

Finally I decided to ask here not only for finding help on this specific issue but also to get a feedback on how master-detail forms can be designed in perspective, perhaps there is a better way or a best practice that is different from this implementation of mine.

---

<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:** [March 9, 2023, 1:38pm UTC](https://forum.inductiveautomation.com/t/pass-pyrow-to-sub-view/70823/2 "2023-03-09T13:38:23Z")

</div>

If you want to use `system.db.runPrepQuery()` will not be able to pass the row directly, as you have discovered.

You will instead need to build up the object.

```auto
instances = []
for row in system.db.runPrepQuery("SELECT * FROM INVOICEROWS WHERE INVOICEID=?", [value]):
    thisRow = {'column1':row['column1'],'column2':row['column2']}
    instances.append({"row":thisRow})

```

or as a comprehension

```auto
instances = {"row":{'column1':row['column1'],'column2':row['column2']} for row in system.db.runPrepQuery("SELECT * FROM INVOICEROWS WHERE INVOICEID=?,[value])}

```

Or if you use `system.db.runNamedQuery()` you can set the return to be json, and then you should be able to work directly with the json object.
