# Report Scripting: Accessing Nested Query with Nested Query

**URL:** <https://forum.inductiveautomation.com/t/report-scripting-accessing-nested-query-with-nested-query/33211>\
**Category:** Ignition\
**Created:** [March 18, 2020, 3:31pm UTC](https://forum.inductiveautomation.com/t/report-scripting-accessing-nested-query-with-nested-query/33211 "2020-03-18T15:31:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tommy](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@tommy](https://forum.inductiveautomation.com/u/tommy)\
**Post date:** [March 18, 2020, 3:31pm UTC](https://forum.inductiveautomation.com/t/report-scripting-accessing-nested-query-with-nested-query/33211/1 "2020-03-18T15:31:36Z")

</div>

I’m working on a report that has two layers of nested queries. I’m having trouble accessing the nested query on the second tier within the scripting data source. Does anyone have an idea how to go about this?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 18, 2020, 3:49pm UTC](https://forum.inductiveautomation.com/t/report-scripting-accessing-nested-query-with-nested-query/33211/2 "2020-03-18T15:49:25Z")

</div>

If you are _ **accessing** _ nested data, look at the docs:

[https://docs.inductiveautomation.com/display/DOC80/Scripting+Data+Source#ScriptingDataSource-NestedQueries](https://docs.inductiveautomation.com/display/DOC80/Scripting+Data+Source#ScriptingDataSource-NestedQueries)

If you want to _ **construct** _ nested data, look at this topic:

> [@Report with Scripted Nested Data](http://forum.inductiveautomation.com/t/report-with-scripted-nested-data/11801/2):
>
> So, I figured this out on my own with a lot of help from inspect.py, which showed me this: Java Type: \<type 'com.inductiveautomation.reporting.common.api.QueryResults'\> M: \<type 'void'\> addNestedQueryResults(\<type 'java.lang.String'\>,\<type '[Lcom.inductiveautomation.reporting.common.api.QueryResults;'\>) M: getCoreResults() returns \<type 'com.inductiveautomation.ignition.common.Dataset'\> M: \<type 'java.util.TreeMap'\> getNestedQueryResults() M: \<type 'java.lang.Object'\> get(\<type 'i…

---

<div class="post-metadata">

**Author:** ![tommy](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@tommy](https://forum.inductiveautomation.com/u/tommy)\
**Post date:** [March 18, 2020, 4:03pm UTC](https://forum.inductiveautomation.com/t/report-scripting-accessing-nested-query-with-nested-query/33211/3 "2020-03-18T16:03:56Z")

</div>

I have been able to access the first layer of the nested query looking at this documentation. However, I’m having trouble accessing the second layer of the nested query in the report scripting. In this case, the RUN\_NUM subquery.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/3/3f8e013facef9aea2d68ed47aad563436a7b0190.png)

---

<div class="post-metadata">

**Author:** ![pdc5067](https://avatars.discourse-cdn.com/v4/letter/p/c6cbf5/32.png) [@pdc5067](https://forum.inductiveautomation.com/u/pdc5067)\
**Post date:** [November 30, 2020, 11:02pm UTC](https://forum.inductiveautomation.com/t/report-scripting-accessing-nested-query-with-nested-query/33211/4 "2020-11-30T23:02:28Z")

</div>

Did you ever figure out how to access the sub-level child queries via scripting? I am trying to accomplish this but I cannot figure out the syntax. Currently I have what is shown in the [Scripting Data Source](https://docs.inductiveautomation.com/display/DOC79/Scripting+Data+Source#:~:text=The%20Script%20data%20source%20allows,for%20use%20in%20the%20report.) page but I included a nested for loop for the sub-level child query.

The furthest I get is an error ‘TypeError: array.array indices must be integers’ when I write:

```auto
	nested = data['NestedQuery_Parent'].getNestedQueryResults() # Gets results from our parent query
	childQuery = nested['Child_Query'] # Gets the subquery we want -- there can be more than one
	subchildQuery = childQuery['subChild_Query'].getNestedQueryResults()

```

where my Nested queries are in the order:  
NestedQuery\_Parent  
-Child\_Query  
–subChild\_Query
