Getting check box information into data table

Im writing an app, that is supposed to store outputs as a string in a datatable and then ask the ones that have entered them to check up to two boxes to further define the information. The outputs are matched using the email address that respondents need to enter on the first page. If a respondent only entered one input, the check boxes are checked and the information makes its way into the data table.

However, if there are two or more outputs given and I check the boxes, then I get this error:

anvil.tables.TableError: More than one row matched this query

My function for the boxes looks as follows, it looks the same for both check boxes and only the respective column names differ:

def check_box_1_change(self, **event_args):
    """This method is called when this checkbox is checked or unchecked"""
    check_row = app_tables.responses.get(email=Globals.mail)
    #check_row = check_row['output']
    #print(check_row)
    if check_row['Energie'] == True:
      check_row['Energie']=False
    else:
      check_row['Energie']=True

I guess I need to specify the output in the function but also get an error when trying this…

Please find attached a clone of my project:

It’s because of 2 things:

  1. For every text box, you add a new row with this function:
@anvil.server.callable
def add_to_table(output,email,Energie,Verkehr):
  #adds the output given to the table in the column 'output'
  app_tables.responses.add_row(output=output,email=email,Energie=Energie,Verkehr=Verkehr)
  1. And so, when you use the line below, you are almost always get back 2 or more rows, which isn’t allowed:

check_row = app_tables.responses.get(email=Globals.mail)

You could change that to check_row = app_tables.responses.get(email=Globals.mail, output=self.item), but that would only kick the can down the road if someone with the same email and output you would get the same issue. It’s probably easier if you change the output to a simple object column, set it to a list, and then append each output to that.

1 Like

Thanks! This actually works, since a respondent who puts in the same output twice will be very rare and if so I guess I can print an error message, if that happens, asking for differing outputs.

1 Like