# How to add selected data to database as list in particular column?

**URL:** <https://forum.inductiveautomation.com/t/how-to-add-selected-data-to-database-as-list-in-particular-column/46093>\
**Category:** Ignition\
**Created:** [April 28, 2021, 7:50am UTC](https://forum.inductiveautomation.com/t/how-to-add-selected-data-to-database-as-list-in-particular-column/46093 "2021-04-28T07:50:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [April 28, 2021, 7:50am UTC](https://forum.inductiveautomation.com/t/how-to-add-selected-data-to-database-as-list-in-particular-column/46093/1 "2021-04-28T07:50:02Z")

</div>

Hi , i have a popup window i that i have **check box**  
when user select the multiple check box or single check and they press add to schedule button  
how to store the check box selected text as list in of database of particular column?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/e/0e6c304ac4d998cfad3b33e4154b7398beea723d.png)

when user select add to scheduled button multiple times . for each click new row has to be added in database and check box selected text should be stored in database row as list

```auto
if event.source.parent.getComponent('CheckBox').selected and event.source.parent.getComponent('CheckBox 1').selected and event.source.parent.getComponent('CheckBox 2').selected :

	sel = "[" + event.source.parent.getComponent('CheckBox').text + "," + event.source.parent.getComponent('CheckBox 1').text + "," + event.source.parent.getComponent('CheckBox 2').text + "]"
elif event.source.parent.getComponent('CheckBox').selected and event.source.parent.getComponent('CheckBox 1').selected:
	sel = "[" + event.source.parent.getComponent('CheckBox').text + "," + event.source.parent.getComponent('CheckBox 1').text + "]"
elif event.source.parent.getComponent('CheckBox').selected and event.source.parent.getComponent('CheckBox 2').selected :
	sel = "[" + event.source.parent.getComponent('CheckBox').text + "," + event.source.parent.getComponent('CheckBox 2').text + "]"

```

i tired script like this for multiple select but this not correct approach

please help me to correct my issue

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [April 28, 2021, 12:20pm UTC](https://forum.inductiveautomation.com/t/how-to-add-selected-data-to-database-as-list-in-particular-column/46093/2 "2021-04-28T12:20:44Z")

</div>

You have repeated yourself a lot in your script. Look to assign values to variables and use loops to cut down on repetitive scripting. the `append()` method will get you what you want.

```auto
cb = event.source.parent.getComponent('Check Box')
cb1 = event.source.parent.getComponent('Check Box 1')
cb2 = event.source.parent.getComponent('Check Box 2')
checkboxes = [cb,cb1,cb2]
selections = []
for checkbox in checkboxes:
	if checkbox.selected:
		selections.append(checkbox.text)
print selections

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [April 28, 2021, 12:27pm UTC](https://forum.inductiveautomation.com/t/how-to-add-selected-data-to-database-as-list-in-particular-column/46093/3 "2021-04-28T12:27:16Z")

</div>

Same concept as @dkhayes117 only slightly more pythonic

```auto
from com.inductiveautomation.factorypmi.application.components import PMIChickBox
comps = event.source.parent.getComponents()

selList = [comp.text for comp in comps if isinstance(comp,PMICheckBox) and comp.selected]

print selList

```

Then if you want to store it in the DB as a string you only need to do

```auto
','.join(selList)

```

Once you pull it back from the DB use split to transform it back to a list

```auto
selList = dbValue.split(',')

```

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [April 28, 2021, 12:29pm UTC](https://forum.inductiveautomation.com/t/how-to-add-selected-data-to-database-as-list-in-particular-column/46093/4 "2021-04-28T12:29:30Z")

</div>

> [@lrose](#):
>
> `comps = event.source.parent.getComponents()`

Thanks for the script. it teaches me a a lot

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [April 28, 2021, 12:32pm UTC](https://forum.inductiveautomation.com/t/how-to-add-selected-data-to-database-as-list-in-particular-column/46093/5 "2021-04-28T12:32:57Z")

</div>

one question i have 2 datasets

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/d/7dfd5782dd2239b312e4f2a58664f64bd5b03b11.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/2/52f510942b22ab1de59db21bfa09b54e49123f62.png)  
both having different row counts  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/c/3cd3cdb168eebe910c655a655455c165c44b3194.png)

in first dataset i want to add a new column( that is second dataset tag column to the first dataset) keeping the time stamp column common

is it possible?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [April 28, 2021, 12:37pm UTC](https://forum.inductiveautomation.com/t/how-to-add-selected-data-to-database-as-list-in-particular-column/46093/6 "2021-04-28T12:37:26Z")

</div>

That question has been answered here:

> [@Combine two datasets](http://forum.inductiveautomation.com/t/combine-two-datasets/45855):
>
> Hi , i have 2 datasets - containing time stamp and tag value i want combine 2 dataset with matching time stamp corresponding data to it one dataset i have 20 rows with time stamp but in another dataset i have only 10 time stamp row. but i want combine them with corresponding value. please help me out. i want add a column from 2nd dataset to first dataset please help me on this

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [April 28, 2021, 12:38pm UTC](https://forum.inductiveautomation.com/t/how-to-add-selected-data-to-database-as-list-in-particular-column/46093/7 "2021-04-28T12:38:38Z")

</div>

ya this is the post i have posted but still now i didn’t got solution

so only again asked

i am trying to do offset concept in chart

but i am failed to do that.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [April 28, 2021, 12:48pm UTC](https://forum.inductiveautomation.com/t/how-to-add-selected-data-to-database-as-list-in-particular-column/46093/8 "2021-04-28T12:48:10Z")

</div>

Because it isn’t possible, as you have been told. I’m not even sure why you would want to do that, what insight into the data will it provide?

You should continue to post in that topic for that problem, not confuse future readers of this topic with information which doesn’t pertain to the original question.
