Here's one I created experimenting with this. The idea being that I wanted a way to loop through an unknown number of table rows, creating a user task for each one. Ultimately, I never implemented it, but it did work in my testing.
It takes a bit to wrap your brain around it, but it's not too complicated once you understand it.
The form itself has three parts:
- A table with a username field. Username is likely something like a lookup populated dropdown.
- A number field outside the table (hidden on the form) with a variable like table_row_count.
- A text field outside the table (hidden on the form) with a variable like current_username.
The fields #2 and #3 are shown in this screenshot, but they will be used by Workflow, not the form, so they don't need anything populated on the form, and can be hidden.
This is what the Forms Process looks like:
This is what the Workflow looks like:
Here's how the process runs through an example:
- Form is submitted - using the example I shared above, I am submitting it with 3 users: Matthew, Jackie, and Ashley. It'll work through these in reverse order, from Ashley, to Jackie, and finally to Matthew.
- First iteration of the workflow runs.
- Delay - waits 1 Minute - this delay exists to ensure that the other steps in the Workflow can run in-between each iteration of the Workflow. It does mean that there will be 1 additional minute of delay in the process for each additional row in the table.
- Retrieve Business Process Variables - gets table>username variables from the form, along with the table_row_count variable.
- Conditional Sequence - this will only be triggered on the first iteration of the workflow - the condition is checking that the table_row_count token pulled in from step #2 is empty. It'll be populated in the first instance, so it will only be true the first time.
- Assign Token Values - Modify Value - this is updating the table_row_count token pulled in from step #2. The value populated in it is based on the table>username token pulled in from step #2, and running the "Value Count" function on it - this basically counts how many rows were in the table. In this example, it's 3.
- Token Calculator - this takes the table_row_count token pulled in from step #2 and subtracts 1 from it. In this example, it's now 2.
- Set Business Process Variables - pushes two values back into the form - filling in those two hidden fields outside the table.
- table_row_count will be populated by the new value from step #4 (in this example, it is 2).
- table_row_count=%(TokenCalculator_New Count)
- current_username will be populated by the value for the current row (the table_row_count token pulled in from step #2 and/or updated in step #3.1 - it is 3 in this example) of the username field in the table (the table > username fields pulled in from step #2).
- current_username=%(RetrieveBusinessProcessVariables_Table\username#[%(RetrieveBusinessProcessVariables_table_row_count)]#)
- Having complete the workflow, this example now has a table_row_count value = 2, and a current_username value = Ashley's username.
- The Parallel Gateway will lead in to two separate paths.
- User Task will assign a task, using the value in the current_username field. In this example, that task is assigned to Ashley.
- The Exclusive Gateway will check the if the table_row_count value is >= 1 (which will return to the Workflow) or if the table_row_count value = 0 (which will end the path). In this example, since table_row_count value = 2, it will return to the Workflow.
- First iteration of the workflow runs.
- Delay - waits 1 Minute - this delay exists to ensure that the other steps in the Workflow can run in-between each iteration of the Workflow.
- Retrieve Business Process Variables - gets the table of usernames from the form, along with the table_row_count variable.
- Conditional Sequence - this will only be triggered on the first iteration of the workflow - the condition is checking that the table_row_count token pulled in from step #2 is empty.
- Assign Token Values - Modify Value - this is updating the table_row_count token pulled in from step #2. The value populated in it is based on the table>username token pulled in from step #2, and running the "Value Count" function on it - this basically counts how many rows were in the table. In this example, it's 3.
- Token Calculator - this takes the table_row_count token pulled in from step #2 and subtracts 1 from it. In this example, it's now 2.
- Set Business Process Variables - pushes two values back into the form - filling in those two hidden fields outside the table.
- table_row_count will be populated by the new value from step #4 (in this example, it is 2).
- table_row_count=%(TokenCalculator_New Count)
- current_username will be populated by the value for the current row (the table_row_count token pulled in from step #2 and/or updated in step #3.1 - it is 3 in this example) of the username field in the table (the table > username fields pulled in from step #2). In this example, it will be Ashley's username.
- current_username=%(RetrieveBusinessProcessVariables_Table\username#[%(RetrieveBusinessProcessVariables_table_row_count)]#)
- Having complete the workflow, the form now has a table_row_count value = 2, and a current_username value = Ashley's username.
- The Parallel Gateway will lead in to two separate paths.
- User Task will assign a task, using the value in the current_username field. In this example, that task is assigned to Ashley.
- The Exclusive Gateway will check the if the table_row_count value is >= 1 (which will return to the Workflow) or if the table_row_count value = 0 (which will end the path). In this example, since table_row_count value = 2, it will return to the Workflow.
- Second iteration of the workflow runs.
- Delay - waits 1 Minute
- Retrieve Business Process Variables
- Conditional Sequence (no longer evaluates as true since the table_row_count was populated on the first iteration).
- Token Calculator - In this example, the value is now 1.
- Set Business Process Variables
- table_row_count will be 1 now in this example.
- current_username will be Jackie's username in this example.
- Having complete the workflow, the form now has a table_row_count value = 1, and a current_username value = Jackie's username.
- The Parallel Gateway will lead in to two separate paths.
- User Task will assign to Jackie in this example.
- The Exclusive Gateway in this example will still return to the workflow because the table_row_count value = 1.
- Third iteration of the workflow runs.
- Delay - waits 1 Minute
- Retrieve Business Process Variables
- Conditional Sequence (no longer evaluates as true since the table_row_count was populated on the first iteration).
- Token Calculator - In this example, the value is now 0.
- Set Business Process Variables
- table_row_count will be 1 now in this example.
- current_username will be Matthew's username in this example.
- Having complete the workflow, the form now has a table_row_count value = 0, and a current_username value = Matthew's username.
- The Parallel Gateway will lead in to two separate paths.
- User Task will assign to Matthew in this example.
- The Exclusive Gateway in this example will now run to the end event because the table_row_count value = 0.
Here's a screenshot of the process following this example, and showing the tasks assigned to the three users:
Hopefully that all makes sense.