Button error: AttributeError: 'NoneType' object has no attribute

Hello

I have created a power table linked to a SQL DB.
This is for a checklist where the user will check if an action has been performed

.
At the end I have a button (Adherencia) to calculate the percentage of the actions performed.
But I keep getting this error:

This is the code I have setup for the button to count the checked boxes and then calculate percentage:

ds = event.source.parent.getComponent('Power Table').Checked count = sum(ds.getValueAt(row, "Checked") for row in range(ds.rowCount)) event.source.parent.getComponent("Numeric Text Field 1").intValue = (count*100)/34

Any Idea what is wrong with the code?
Also if possible, is there a code to clear the check boxes with the same button?

Thank you in advance.
Regards.

ds = event.source.parent.getComponent('Power Table').data
count = sum(ds.getValueAt(row, "Checked") for row in range(ds.rowCount))
event.source.parent.getComponent("Numeric Text Field 1").intValue = (count*100)/34

I'm not sure you want to use the same button, however, this code should clear the check boxes:

ds = event.source.parent.getComponent('Power Table').data
for row in range(ds.rowCount)):
     ds = system.dataset.setValue(ds,row,'Checked',0)
event.source.parent.getComponent('Power Table').data = ds

Thank you but now the error changed to:
Traceback (most recent call last):

File “event:actionPerformed”, line 2, in

TypeError: unsupported operand type(s) for +: ‘int’ and 'NoneType’

Any Idea what else can be wrong

Thanks

I’m not sure what the sum function is, I assume it is a built in function, however, it looks like the error seems to be in that function.

Try the following code to get the sum of checked rows:

ds = event.source.parent.getComponent('Power Table').data
count = 0
for row in range(ds.rowCount):
	count += ds.getValueAt(row,'Checked')
event.source.parent.getComponent('Numeric Text Field 1').intValue = (count*100)/34

If you get the same error, you may need to force the type of the value to an integer value

ds = event.source.parent.getComponent('Power Table').data
count = 0
for row in range(ds.rowCount):
	count += int(ds.getValueAt(row,'Checked'))
event.source.parent.getComponent('Numeric Text Field 1').intValue = (count*100)/34

Thank you I tried both options.
First one gave same error.
Second one shows this error:

Can´t think of a way to get the value to be integer or a number.

If you post your script here somebody may be able to spot the problem.

I created a new display with just a power table and a button. I set the power table data table up with two columns, a string column name and a boolean column Checked.

I put the following code in the button action preformed event and each variance of code executed without error and calculated the correct number of checked boxes.

ds = event.source.parent.getComponent('Power Table').data
count = 0
for row in range(ds.rowCount):
	count += ds.getValueAt(row,'Checked')
	
print count

count = 0
for row in range(ds.rowCount):
	count += int(ds.getValueAt(row,'Checked'))

print count

print sum(ds.getValueAt(row,'Checked') for row in range(ds.rowCount))

Resulted in:

This makes me believe that your column ‘Checked’ is some data type that were not expecting. Can you provide more detail on how you have the columns setup, or provide the code for how you fill the table?

1 Like

Finally I was able to find the error with help of your code just changed the int for bool in this line:

count += int(ds.getValueAt(row,'Checked'))

So the code now work like this:

count += bool(ds.getValueAt(row,'Checked'))
1 Like