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
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
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
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.