# Pydataset in SFC

**URL:** <https://forum.inductiveautomation.com/t/pydataset-in-sfc/8845>\
**Category:** Ignition\
**Created:** [August 1, 2014, 7:59pm UTC](https://forum.inductiveautomation.com/t/pydataset-in-sfc/8845 "2014-08-01T19:59:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zackscriven](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zackscriven/32/7213_2.png) [@zackscriven](https://forum.inductiveautomation.com/u/zackscriven)\
**Post date:** [August 1, 2014, 7:59pm UTC](https://forum.inductiveautomation.com/t/pydataset-in-sfc/8845/1 "2014-08-01T19:59:11Z")

</div>

Hi I am having trouble running a query in an SFC step.

[code]# reset index

```
chart.index = 1

```

# query for routine where the remainder of chart.index divided by priorty is equal to 0

```
query = "SELECT path, priority FROM routine WHERE ?%priority = 0"
params = chart.index
chart.routine_dataset = system.db.runPrepQuery(query,[params])	

```

# not sure if this is necessary

```
data = chart.routine_dataset

```

# set the number of rows of the dataset to determine the number of times to loop through it

```
chart.routine_dataset_length = data.rowCount

[/code]

```

The next step this is what I am doing to write to the tag paths stored in the dataset.

[code] row = chart.routine\_dataset\_index # determine row based on routine dataset index

```
col = "path" #	we want the column named Path

chart.routine_path = chart.routine_dataset.getValueAt(row,col) #get the tag path based on row and column

system.tag.write(chart.routine_path,1) #	write the demand poll bit to true

[/code]

```

followed by

```auto
	chart.routine_dataset_index = chart.routine_dataset_index + 1
```

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [August 3, 2014, 4:28am UTC](https://forum.inductiveautomation.com/t/pydataset-in-sfc/8845/2 "2014-08-03T04:28:14Z")

</div>

Hey Zack,

It looks like you may need to understand differences between PyDataSets and Datasets better. They are two different data structures that are related but different. They both hold the same kind of data but access it differently. Check out PyDataSets and Datasets in this documentation: [inductiveautomation.com/support … atatyp.htm](https://inductiveautomation.com/support/usermanuals/ignition/index.html?working_with_different_datatyp.htm)

Look at the examples of how data is accessed using PyDataSets and how data is accessed using Datasets. A database query returns a PyDataSet. So your code needs to access the data using the PyDataSet style unless you turn it into a Dataset.

Python scripts in SFC charts are gateway scripts. My article on debugging and testing gateway scripts may help you find out why scripts aren’t working. My article is here: [perfectabstractions.com/blog … nt-scripts](http://www.perfectabstractions.com/blog/debugging-and-testing-gateway-event-scripts)

Awesome that you are using SFC charts. I’d love to hear your experiences with them sometime.

Best,
