# Getting data from a data source in reports using scripting

**URL:** <https://forum.inductiveautomation.com/t/getting-data-from-a-data-source-in-reports-using-scripting/36684>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [July 14, 2020, 2:36pm UTC](https://forum.inductiveautomation.com/t/getting-data-from-a-data-source-in-reports-using-scripting/36684 "2020-07-14T14:36:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![boster281](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@boster281](https://forum.inductiveautomation.com/u/boster281)\
**Post date:** [July 14, 2020, 2:36pm UTC](https://forum.inductiveautomation.com/t/getting-data-from-a-data-source-in-reports-using-scripting/36684/1 "2020-07-14T14:36:32Z")

</div>

In a report I have a SQL query data source that gets all of my results. One of those results is a Pass/Fail int. I want to use this int to drive a color change and a Pass Fail read out.

1. can you define one of the SQL query results as a parameter that can then be used in other Data sources
2. can you get one piece of data out of a script query to use?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/4/74dfb7a0682bc58fa9d4a4e86797d71f71571109.png)

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [July 14, 2020, 2:47pm UTC](https://forum.inductiveautomation.com/t/getting-data-from-a-data-source-in-reports-using-scripting/36684/2 "2020-07-14T14:47:42Z")

</div>

> [@boster281](#):
>
> can you define one of the SQL query results as a parameter that can then be used in other Data sources

Yes you can. Try This:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/7/47d5d65223f325319aab8cccbc121b194aa8afcf.png)  
You should have 2 identical data sources in the design tab, test1 and test2.

As for your 2nd question, you can definitely use scripting to get 1 piece of data.

---

<div class="post-metadata">

**Author:** ![boster281](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@boster281](https://forum.inductiveautomation.com/u/boster281)\
**Post date:** [July 14, 2020, 2:52pm UTC](https://forum.inductiveautomation.com/t/getting-data-from-a-data-source-in-reports-using-scripting/36684/3 "2020-07-14T14:52:44Z")

</div>

Thank you that will be very helpful in something else I am working on.  
But what I meant in that part of the question was more for the Query data source.

Like this  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/e/4eb34034d4968cc54043ea2b45b31cbca0240db0.png)

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [July 14, 2020, 2:54pm UTC](https://forum.inductiveautomation.com/t/getting-data-from-a-data-source-in-reports-using-scripting/36684/4 "2020-07-14T14:54:28Z")

</div>

Replace **Test\_Pressure** with a **?**  
A parameter box should appear at the bottom.

Edit; screenshot

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

---

<div class="post-metadata">

**Author:** ![boster281](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@boster281](https://forum.inductiveautomation.com/u/boster281)\
**Post date:** [July 14, 2020, 6:20pm UTC](https://forum.inductiveautomation.com/t/getting-data-from-a-data-source-in-reports-using-scripting/36684/5 "2020-07-14T18:20:58Z")

</div>

The ? only seems to work to retrieve a parameter for a where clause not insert a returned result into a parameter.

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [July 14, 2020, 6:45pm UTC](https://forum.inductiveautomation.com/t/getting-data-from-a-data-source-in-reports-using-scripting/36684/6 "2020-07-14T18:45:57Z")

</div>

With what you posted, it looks like your query only returns one row, the Test\_Pressure is a parameter your feeding into the query. Are you trying to feed the result of the query back into the parameter? If you want to write back into the parameter you would have to do that through a script. I’m not sure with the example you gave why you would want to do that though. If you returned just one row of data, you can reference the value directly from the data returned from the query, in your report.

If you want to take the results of your one row returned and feed the Test\_Pressure that was returned back into a parameter you can try something like:

```auto
rData = data['query'].getCoreResults()
data['Test_Pressure'] = rData.getValueAt(0,'Test_Pressure')

```

Or

```auto
data['Test_Pressure'] = data['query'].getCoreResults().getValueAt(0,'Test_Pressure')

```

---

<div class="post-metadata">

**Author:** ![boster281](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@boster281](https://forum.inductiveautomation.com/u/boster281)\
**Post date:** [July 14, 2020, 6:48pm UTC](https://forum.inductiveautomation.com/t/getting-data-from-a-data-source-in-reports-using-scripting/36684/7 "2020-07-14T18:48:45Z")

</div>

That makes sense. I tried using getCoreResults before but missed the GetValueAt portion.

Thanks
