Radio Button Group Selected

I have 4 radio buttons that I have grouped together in order for the user to only select 1 button. I am trying to reference the button now to see if it is selected:
excellentSelected = event.source.parent.getComponent(‘Radio Button Excellent’).selected

The buttons are in “Group” in the same root container. any ideas here? I could always use a drop down list.

Grab the area number and machine name from the components we added to the window.

dieIDInput = event.source.parent.getComponent(‘Formatted Text Field’).text
excellentSelected = event.source.parent.getComponent(‘Radio Button Excellent’).selected
goodSelected = event.source.parent.getComponent(‘Group / Radio Button Good’).selected
poorSelected = event.source.parent.getComponent(‘Group / Radio Button Poor’).selected
criticalSelected = event.source.parent.getComponent(‘Group / Radio Button Critical’).selected
repairYes = event.source.parent.getComponent(‘Group 1 / Radio Button Repair Yes’).selected
repairNo = event.source.parent.getComponent(’ Group 1 / Radio Button Repair No’).selected
comments = event.source.parent.getComponent(‘Text Area Comments’).text

#Root Container.Group.Radio Button Excellent.selected
#event.source.parent.getComponent(‘Group / Radio Button Excellent’).selected

A call to our Named Query, inserting the two parameters using dictionary syntax.

system.db.runNamedQuery(“Die Inspection”, {“dieIDInput”:dieIDInput, “excellentSelected”

Tip: use the </> code formatting button to preserve code indentation and apply syntax highlighting. It’s essential for Python and makes any code much easier to read. There’s an edit button (pencil icon) below your post so you can fix it.

The post seems to be for a Vision application rather than Perspective so if you add the Vision tag you may attract the Vision experts.

It’s not clear why you have formatted two of your sentences as headings. It may be an accident but it is confusing.

A simple way would be to add a custom property to the group. (Right-click | Customizers | Custom property.) Set this as an integer or string depending what you want back. I suspect you want a string.

Vision radio custom property

Create an event on each button to write dieIDInput or excellentSelected or whatever to your custom property. You can then read that wherever you want.

I will give this a go! I have them set as boolean in my database table as I am just looking to see which is selected. Everything works fine and writes to my table if I ungroup my radio buttons.

Is there a way to address the group followed by the component? Almost like you do for the folder and then script when calling for a named query. I just started working in Ignition two weeks ago so this is all very new to me.

Please post formatted code rather than screengrabs of code so we can copy and edit them in our answers.

I suggest that you are not going about this the right way. Since only one ‘condition’ can be selected you should have a ‘condition’ column in your database and that would contain the selected option. That’s why I suggested storing that value as a custom property. It will also greatly simplify your code to just this:

  "Die Inspection", 
    "dieID": event.source.parent.getComponent('txtDieId').text,
    "condition": <path to condition custom property>,
    "repair": <path to repair custom property>,
    "comments": event.source.parent.getComponent('txtaComments').text

Retrieving the data will now be much simpler as well.

I wouldn’t use a script at all and in fact I recommend against it. Scripts only run on events so your combined status will become out of sync for example on startup or lf the radio buttons are changed externally, changed by another client etc etc. What you want is a simple expression binding that checks the status of each radio button sequentially and returns an integer value based on which is on.

If{{}, 1,
If{{}, 2,
1 Like

Wrong opening bracket. It should be (and with tip for substituting a value) …

If({}, 'Excellent',
If({}, 'Good',

Oops, typed on my phone, hard to see the difference in the brackets :grimacing: I do prefer the strings instead

This is what I came up with:

dieIDInput = event.source.parent.getComponent('Formatted Text Field').text
conditionInput = event.source.parent.getComponent('Group').components
for components in conditionInput:
	if components.selected == True:
		conditionInput = components.text
repairInput = event.source.parent.getComponent('Group 1').components
for components in repairInput:
	if components.selected == True:
		repairInput = components.text

comments = event.source.parent.getComponent('Text Area Comments').text

# A call to our Named Query, inserting the parameters using dictionary syntax.
system.db.runNamedQuery("Die Inspection", {"dieIDInput":dieIDInput, "conditionInput":conditionInput, "repairInput":repairInput, "comments":comments,})

Thank you both for all of the help. Sorry for the poor posting early on as this was a first for me.

That looks better.

While I think Ignition might tolerate it, you have an erroneous comma at the end: ... comments,}) should be ... comments}).