Count number of selected checkboxes in repeater


I am trying to get the running total of selected rows in a repeater by updating a global variable by one every time the checkbox in the repeater row is selected.

I have set a global variable to 0 and on the repeater loaded interaction I try to increment this by 1.

The Case looks like this:

If "[[Item.Assign]]" equals "true"
Set Selected/Checked
  This to "true"
Set Variable Value
  UnassignedCasesCount to "[[UnassignedCasesCount + 1]]"

How can I set the global variable to the correct count value? Or at least the total number of selected rows in the repeater?

At the moment it des not increment by 1 but multiples every time a checkbox is selected.


Using a global variable works well for this (or text on a widget, hidden or not.) It looks like you also have a column in your repeater dataset to keep track of which rows are checked/selected, with Item.Assign, and that works well, too. I think the most reliable way to handle “repeater counts” (and track the status of a repeater row/widget in general) is to basically do everything in the repeater’s Item Loaded event.

Based on your code snippet, it looks like it comes from the checkbox widget’s Click or Tap event. That is likely where your “increment by multiples” bug is coming from.

When the checkbox widget’s selection state is changed, it should update “This row” to the state of checkbox (true or false). Then in a conditional case in Item Loaded the checkbox widget’s selection state can be set (to [[Item.Assign]] ) and your global variable can be incremented. To make this work correctly, you’ll need to initialize the value of the global variable (to “0”) each time the repeater is updated. To do this, add a case statement with If [[Item.isFirst]] equals "true" set UnassignedCasesCount to "0" and then in a subsequent case statement increment the value if [[Item.Assign]] equals “false” (assuming that when checkbox is selected/checked then something is “unassigned” and this is what you are counting.)

It might be easier to demonstrate this if you upload a sample .rp file, but here is a summary of the method I’m recommending:

Checkbox widget:
Selected event:

Update Rows
(repeater) set Assign to “false” for This

Unselected event:

Update Rows
(repeater) set Assign to “true” for This

In the repeater’s Item Loaded event:

Case first row, initialize counter
If [[Item.isFirst]] equals “true”
Set Variable Value
UnassignedCasesCount to “0”

Case row is checked
If [[Item.Assign]] equals “false”
Set Selected/Checked
myCheckbox to “true”
Set Variable Value
UnassignedCasesCount to [[UnassignedCasesCount + 1]]