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

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?

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

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

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.

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
2 Likes

Same concept as @dkhayes117 only slightly more pythonic

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

','.join(selList)

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

selList = dbValue.split(',')
1 Like

Thanks for the script. it teaches me a a lot

one question i have 2 datasets



both having different row counts
image

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?

That question has been answered here:

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.

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.

1 Like