# Creating and adding to a dataset

**URL:** <https://forum.inductiveautomation.com/t/creating-and-adding-to-a-dataset/1391>\
**Category:** Archived Topics\
**Created:** [November 30, 2009, 5:13pm UTC](https://forum.inductiveautomation.com/t/creating-and-adding-to-a-dataset/1391 "2009-11-30T17:13:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [November 30, 2009, 5:13pm UTC](https://forum.inductiveautomation.com/t/creating-and-adding-to-a-dataset/1391/1 "2009-11-30T17:13:19Z")

</div>

I’m trying to create a dataset of a user’s roles on startup and pass them to a window for display in a list.

I’ve tried the following code`data = []
for role in fpmi.security.getRoles():
	data = fpmi.dataset.addRow(data,[role])
fpmi.nav.openWindow("Window 1",{'roles' : data})
`but I get an error in the addRow line that the 1st arg can’t be coerced to a DataSet. I’m obviously not initialising the dataset variable correctly…

---

<div class="post-metadata">

**Author:** ![MickeyBob](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@MickeyBob](https://forum.inductiveautomation.com/u/MickeyBob)\
**Post date:** [November 30, 2009, 5:31pm UTC](https://forum.inductiveautomation.com/t/creating-and-adding-to-a-dataset/1391/2 "2009-11-30T17:31:26Z")

</div>

Al,

I don’t think you can add a row directly to a dataset.

I think you would have to create a roles list and a headers list and use the fpmi.dataset.toDataSet(#2) method to convert them to a dataset.

See the example in the manual.

[Edit]  
Try this:

`roles = [[role] for role in fpmi.security.getRoles()]
headers = ["role"]
data = fpmi.dataset.toDataSet(headers, roles)`[/Edit]

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [November 30, 2009, 6:06pm UTC](https://forum.inductiveautomation.com/t/creating-and-adding-to-a-dataset/1391/3 "2009-11-30T18:06:14Z")

</div>

Hi MickeyBob,

Thanks for the tip. I managed to get it working with the following code:`headers = ["Role"]
data = []
for role in fpmi.security.getRoles():
	data.append([role])
myDataset= fpmi.dataset.toDataSet(headers, data)
fpmi.nav.openWindow("Window 1",{'roles' : myDataset})`  
[Edit]  
I like the ‘3 lines for the price of 1’ Python in your code! Very compact.  
[/Edit]

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [November 30, 2009, 6:54pm UTC](https://forum.inductiveautomation.com/t/creating-and-adding-to-a-dataset/1391/4 "2009-11-30T18:54:17Z")

</div>

I had a further problem displaying the dataset in a list. If I created an empty dataset dynamic property and tried to bind it to a dropdown list, it would bring up the following error:`Error setting dropdown data for dropdown 'drpRoles':Illegal dropdown dataset: no columns.
`This is displayed at runtime even when the dataset being passed in contains data.

The only way I found round this problem was to create a dummy column in the dataset dynamic variable. This is replaced at runtime by the data being passed in without bringing up an error.

---

<div class="post-metadata">

**Author:** ![MickeyBob](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@MickeyBob](https://forum.inductiveautomation.com/u/MickeyBob)\
**Post date:** [November 30, 2009, 8:41pm UTC](https://forum.inductiveautomation.com/t/creating-and-adding-to-a-dataset/1391/5 "2009-11-30T20:41:44Z")

</div>

Al,

I couldn’t replicate your problem in the runtime, just in the development mode, and only then before I “initialized” the list with an empty dataset. Try opening the dataset editor from the properties window and adding a single column. You don’t have to add any rows to the dataset.

Attached is a quick window I put together.  
[RolesDemo.fwin](https://us1.discourse-cdn.com/inductiveautomation/original/1X/0ac3654f8f4c9ef77176a46a173fd5ba5cb071a1.fwin) (7.27 KB)

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [November 30, 2009, 8:47pm UTC](https://forum.inductiveautomation.com/t/creating-and-adding-to-a-dataset/1391/6 "2009-11-30T20:47:05Z")

</div>

Thanks MickeyBob, this is like the solution I came up with. I did get the error in the runtime as well - I was running it as an applet, in case that makes any difference.
