# Create dataset from a function

**URL:** <https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998>\
**Category:** Ignition\
**Created:** [September 23, 2020, 8:25pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998 "2020-09-23T20:25:49Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![steven.cox](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.cox/32/18589_2.png) [@steven.cox](https://forum.inductiveautomation.com/u/steven.cox)\
**Post date:** [September 23, 2020, 8:25pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998/1 "2020-09-23T20:25:49Z")

</div>

Hi all,

I am very new to Ignition and scripting so I am learning on multiple fronts. I am working on a sample project just to learn.

I want to split the results of system.project.getProjectNames() into a single column dataset.

I thought I would use split() to do this but have not been able to.

I ultimately want to this dataset on a dropdown to select a project to retarget.

All help and advice is much appreciated.

Thanks, Steven

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [September 23, 2020, 8:32pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998/2 "2020-09-23T20:32:00Z")

</div>

That function returns a list of names (an array in other language terms).  
To convert to a dataset to use on a dropdown you need to add each element into a dimensional list, in this case a single dimensional list. Think, if you have multiple columns in your table, you would have multiple dimensions to the table list.

```auto
projectNames = system.project.getProjectNames() 
data=[[projectName] for projectName in projectNames] 
ds = system.dataset.toDataSet(['projectName'], data)
dropDownObj.data = ds

```

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [September 23, 2020, 8:35pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998/3 "2020-09-23T20:35:11Z")

</div>

~~I’m guessing projectMames will give you some trouble.~~ 😀

Problem solved.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [September 23, 2020, 8:39pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998/4 "2020-09-23T20:39:41Z")

</div>

I would blame autocucumber, but I think it was more anti-dexterous fingers

---

<div class="post-metadata">

**Author:** ![steven.cox](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.cox/32/18589_2.png) [@steven.cox](https://forum.inductiveautomation.com/u/steven.cox)\
**Post date:** [September 23, 2020, 9:34pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998/5 "2020-09-23T21:34:31Z")

</div>

This is what I want to do. How do I get this dataset bound the dataset property on the dropdown?

Do I need to create a DB table?

Sorry for the fundamental questions but this is very new to me.

Thanks, Steven

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [September 23, 2020, 9:58pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998/6 "2020-09-23T21:58:38Z")

</div>

Vision or Perspective?

---

<div class="post-metadata">

**Author:** ![steven.cox](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.cox/32/18589_2.png) [@steven.cox](https://forum.inductiveautomation.com/u/steven.cox)\
**Post date:** [September 23, 2020, 10:34pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998/7 "2020-09-23T22:34:57Z")

</div>

I’m sorry, Vivion

thanks, steven

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 25, 2020, 3:11pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998/8 "2020-09-25T15:11:09Z")

</div>

> [@steven.cox](#):
>
> How do I get this dataset bound the dataset property on the dropdown?

I would put it in the window's InternalFrameActivated event. This event fires each time the window is activated.

---

<div class="post-metadata">

**Author:** ![steven.cox](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.cox/32/18589_2.png) [@steven.cox](https://forum.inductiveautomation.com/u/steven.cox)\
**Post date:** [September 25, 2020, 3:45pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998/9 "2020-09-25T15:45:33Z")

</div>

@JordanCClark that sounds like a good idea. Now if I new how to do that, that would be great.

InternalFrameActivated is not on the scripting event handler list for the main window or the component.

How would I go about doing this?

Thanks, teven

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [September 25, 2020, 4:12pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998/10 "2020-09-25T16:12:53Z")

</div>

[https://docs.inductiveautomation.com/display/DOC80/Component+Events](https://docs.inductiveautomation.com/display/DOC80/Component+Events)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 25, 2020, 5:00pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998/11 "2020-09-25T17:00:23Z")

</div>

Right-click on the window name in the project tree. Note: The window has to be open, or it will be greyed out.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/a/1aab7d7a9c76cca16df00dc4f23d32d7c513cb2a.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/0/0019c22f8e8f00c0adff50dc98dd23e67a5f87cb.png)

---

<div class="post-metadata">

**Author:** ![steven.cox](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.cox/32/18589_2.png) [@steven.cox](https://forum.inductiveautomation.com/u/steven.cox)\
**Post date:** [September 25, 2020, 5:40pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998/12 "2020-09-25T17:40:05Z")

</div>

@JordanCClark thank you for the help! The dropdown component does not have the internalFrame event handlers.

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

Am I missing something? This is version 8.0.16

I tried using the mouseClicked and received this error.

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

Seems this would be a solution for this object but I must have something set wrong.

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

Again, thanks for the help and for showing I can put images int he forum.

Thanks, Steven

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [September 25, 2020, 6:08pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998/13 "2020-09-25T18:08:00Z")

</div>

You’ll need to access dropDownObj via `event.source.getComponent("dropDownObj").data` or something similar. The easiest way to get the correct path is to use the insert property button at top right of script editor (above insert tag button) to navigate to the component:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/d/2da25377f283e24e7368623c346dc71bda7b971f.png)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 25, 2020, 6:33pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998/14 "2020-09-25T18:33:30Z")

</div>

> [@steven.cox](#):
>
> The dropdown component does not have the internalFrame event handlers.

Components don't have them. Windows do. 😉

> [@JordanCClark](#):
>
> Right-click on the **window name** in the project tree.

```python
dropDownObj = system.gui.getParentWindow(event).getComponentForPath('Root Container.Dropdown')

projectNames = system.project.getProjectNames() 
data=[[projectName] for projectName in projectNames] 
ds = system.dataset.toDataSet(['projectName'], data)
dropDownObj.data = ds

```

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [September 25, 2020, 6:45pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998/15 "2020-09-25T18:45:47Z")

</div>

@JordanCClark’s code should do the trick in the internalFrame event. If you want to put the code on the component, you’d put it in a property change event checking for the componentRunning property:  
`if event.propertyName == "componentRunning":`

---

<div class="post-metadata">

**Author:** ![steven.cox](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.cox/32/18589_2.png) [@steven.cox](https://forum.inductiveautomation.com/u/steven.cox)\
**Post date:** [September 25, 2020, 6:49pm UTC](https://forum.inductiveautomation.com/t/create-dataset-from-a-function/38998/16 "2020-09-25T18:49:13Z")

</div>

@witman, Thats what I was missing!! I forgot about the insert property button. Makes a lot more since now. Especially when I went back and added it to the internalFrameActivated event on the main window.

@JordanCClark, I was missing the correct path to the dropdown dataset property when I tried it in the window.

Thank y’all so much for the help. Now on to the next step.

Thanks, Steven
