# Perspective table. Scripting the data into the table

**URL:** <https://forum.inductiveautomation.com/t/perspective-table-scripting-the-data-into-the-table/35555>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [June 11, 2020, 3:01pm UTC](https://forum.inductiveautomation.com/t/perspective-table-scripting-the-data-into-the-table/35555 "2020-06-11T15:01:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JorgeC](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@JorgeC](https://forum.inductiveautomation.com/u/JorgeC)\
**Post date:** [June 11, 2020, 3:01pm UTC](https://forum.inductiveautomation.com/t/perspective-table-scripting-the-data-into-the-table/35555/1 "2020-06-11T15:01:31Z")

</div>

Im just starting to get the hang out of the scripting, and i used to test some scripts on vision that work perfectly fine and that don´t work anymore on perspective.  
Im trying to put data from a SQL table into a perspective table by pressing a button but without doing a named query, the whole thing by scripting.  
Any idea to where to start? i was thinking to do it all “local” by adding the script to a method in the button, and then call it on the event of cliking on it, so that it gives all the data to the table.

---

<div class="post-metadata">

**Author:** ![dkylep](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@dkylep](https://forum.inductiveautomation.com/u/dkylep)\
**Post date:** [June 11, 2020, 3:29pm UTC](https://forum.inductiveautomation.com/t/perspective-table-scripting-the-data-into-the-table/35555/2 "2020-06-11T15:29:09Z")

</div>

I’m not sure how much help you need but it’s not too hard.

In designer, right click on your button and click ‘configure events’. In the event configuration window select ‘onClick’ and then click the ‘+’ button. Select ‘script’ from the list. Now you have a place to write your script for the onClick event for that button.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/2/27c678bdb5d31097ba3eba3efa7727e56e836ed7.png)

Here’s some pseduo code that will help a little.

```auto
#create a query string
query="SELECT Col1,Col2 FROM Table"

#here's the command to run the query
returnedData = system.db.runQuery(query,"DBname")

#I don't recall if runquery returns a dataset, i think it does
#if it is a dataset than you just set the table property 'data' = to the sql return
self.getSibling("TableName").props.data = returnedData

```

This is assuming you have a database connected to your gateway. Hope this is enough to get you started.

---

<div class="post-metadata">

**Author:** ![JorgeC](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@JorgeC](https://forum.inductiveautomation.com/u/JorgeC)\
**Post date:** [June 11, 2020, 3:44pm UTC](https://forum.inductiveautomation.com/t/perspective-table-scripting-the-data-into-the-table/35555/3 "2020-06-11T15:44:44Z")

</div>

It actually worked perfectly, Im going to try adding parameters and do experiments with this.  
Thank you!

---

<div class="post-metadata">

**Author:** ![ahawes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ahawes/32/36337_2.png) [@ahawes](https://forum.inductiveautomation.com/u/ahawes)\
**Post date:** [July 14, 2022, 1:38pm UTC](https://forum.inductiveautomation.com/t/perspective-table-scripting-the-data-into-the-table/35555/4 "2022-07-14T13:38:13Z")

</div>

Tagging this so I can test it on my project.
