Suppose you have a task that you want to be executed multiple times simultaneously by different users within the same instance of a Workflow process.
To implement this, first, you need to create the following relevant data:
- Users: Records of the users to whom the tasks will be assigned.
- Approved: Status of the tasks.
- CantUsers: Number of users.
Make sure that the relevant data Users and Approved have the Dimension property set as Vector to store multiple values.
After creating the relevant data, create a diagram with: a task where the users are selected, a task that will be assigned to these users, and an exclusive gateway that verifies that the users tasks have been approved. The flow from the gateway may continue to the end or the first task.
In the initial task, you must add the user IDs to the relevant data Users. Below is an example of how to do this:
Event start
&WorkflowOrganizationalModel = &WorkflowServer.GetOrganizationalModel()
&WorkflowUsers = &WorkflowOrganizationalModel.ListUsers(&WorkflowFilter)
Endevent
Event Grid1.Refresh
&WorkflowUsers = &WorkflowOrganizationalModel.ListUsers(&WorkflowFilter)
EndEvent
Event Grid1.Load
For &WorkflowUser in &WorkflowUsers
&Name = &WorkflowUser.Id
Grid1.Load()
Endfor
Endevent
Event &Select.Click
if &Select
&WorkflowApplicationData = &workflowContext.ProcessInstance.GetApplicationDataByName('Users')
&WorkflowApplicationData.Add(&Name)
commit
else
&Removed = false
&WorkflowApplicationData = &workflowContext.ProcessInstance.GetApplicationDataByName('Users')
&i = 1
Do while not &Removed and &i<=&WorkflowApplicationData.Count
if &Name = &WorkflowApplicationData.GetValue(&i)
&WorkflowApplicationData.Remove(&i)
commit
&Removed = True
endif
&i = &i +1
EndDo
endif
EndEvent
Event 'Ok'
&WorkflowApplicationData = &workflowContext.ProcessInstance.GetApplicationDataByName('Users')
&WorkflowApplicationData2 = &workflowContext.ProcessInstance.GetApplicationDataByName('CantUsers')
&WorkflowApplicationData2.NumericValue = &WorkflowApplicationData.Count
commit
return
Endevent
Where:
&WorkflowUsers (WorkflowUser data type, collection)
&Name (Character(100) data type)
&Select (Boolean data type)
&i (Numeric data type)
&Removed (Boolean data type)
&WorkflowApplicationData2 (WorkflowApplicationData data type)
Once the users are selected, the Loop Task should be configured to create one instance for each user setting its properties as follows:
Then, when the flow reaches this task, it will create as many instances of the task as indicated by the Expression rule property and automatically will assign the instances to the users stored in the relevant data Users.
The Flow condition property allows you to configure whether to advance the flow when all the multiple instances are completed or each time one of them is completed.
As an example, in the loop task, users must choose to approve or disapprove it, storing this in the relevant data Approved:
Event 'Approve'
&WorkflowContext.ProcessInstance.GetApplicationDataByName('Approved').Add('Approved')
commit
Endevent
Event 'Disapprove'
&WorkflowContext.ProcessInstance.GetApplicationDataByName('Approved').Add('Disapproved')
commit
Endevent
Finally, an Exclusive Gateway with an associated procedure verifies that all tasks have been approved; if so, it ends the process; otherwise, it returns to the initial task. It can be done with a condition procedure as follows:
ConditionProc:
Rules
parm( in:&WorkflowProcessDefinition, in:&WorkflowProcessInstance, in:&WorkflowWorkitem, out:&conditionCode);
Source
&WorkflowApplicationData = &WorkflowProcessInstance.GetApplicationDataByName('Approved')
&conditionCode = 1
&i = 1
Do while &conditionCode = 1 and &i<=&WorkflowApplicationData.Count
if &WorkflowApplicationData.GetValue(&i) = 'Disapproved'
&conditionCode = 0
endif
&i = &i + 1
Enddo
Where:
&WorkflowUsers (WorkflowUser data type, collection)
&Name (Character(100) data type)
&Select (Boolean data type)
&i (Numeric data type)
&Removed (Boolean data type)
&WorkflowApplicationData2 (WorkflowApplicationData data type)