# Create exception for PartType and Orders \< 50

**URL:** <https://forum.inductiveautomation.com/t/create-exception-for-parttype-and-orders-50/73352>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [May 6, 2023, 1:05am UTC](https://forum.inductiveautomation.com/t/create-exception-for-parttype-and-orders-50/73352 "2023-05-06T01:05:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yarden\_Levy](https://avatars.discourse-cdn.com/v4/letter/y/77aa72/32.png) [@Yarden\_Levy](https://forum.inductiveautomation.com/u/Yarden_Levy)\
**Post date:** [May 6, 2023, 1:05am UTC](https://forum.inductiveautomation.com/t/create-exception-for-parttype-and-orders-50/73352/1 "2023-05-06T01:05:42Z")

</div>

I want to create a filterList for exception parts to not be sent to the excel file. I also want to exclude count of orders over 50. I know I can filter orders within the SQL Query but I want to do it within the script. Any help is appreciated!

```auto
import datetime    	    
currDate = system.date.now()

data = system.db.runNamedQuery('ODS/yardenTest/ordersAvailable')

filterList = ['']
dataNew = []

for row in data:
	if row['PartType'] in filterList:
		dataNew.append(list(row))

print(dataNew)
file = system.dataset.toExcel(True,[dataNew])
filePath = "C:\\Users\\YardenLevy\\Documents\\LowProductionOrders" + system.date.format(currDate, "MM-dd-yy") + ".xlsx"
system.file.writeFile(filePath, file)

```

---

<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:** [May 8, 2023, 4:02pm UTC](https://forum.inductiveautomation.com/t/create-exception-for-parttype-and-orders-50/73352/2 "2023-05-08T16:02:13Z")

</div>

Regular datasets (returned by named queries) are not iterable. Convert to a PyDataset before your loop.

---

<div class="post-metadata">

**Author:** ![Yarden\_Levy](https://avatars.discourse-cdn.com/v4/letter/y/77aa72/32.png) [@Yarden\_Levy](https://forum.inductiveautomation.com/u/Yarden_Levy)\
**Post date:** [May 8, 2023, 4:17pm UTC](https://forum.inductiveautomation.com/t/create-exception-for-parttype-and-orders-50/73352/3 "2023-05-08T16:17:21Z")

</div>

Yep, I figured out my mistake and got it sorted. I created a new dataset and appended the data from the named query into it, then iterated the list.
