Synchronize tokens with Each Token option

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > Process wizard > Model Process > Modeling for execution > Sub-Processes > Understanding Multiple Sub-Processes > Multiple Sub-Processes concepts >

Synchronize tokens with Each Token option

Overview

When using Each token option as Exit mode, users face a common problem: handling more than one active token in parts of the process, where only one should be active.

Bear in mind that all the information entered in an Activity is actually saved in the database (and thus updated in other opened Activities) when the end user clicks on Next, or finishes it. It is important to notice that if an Activity is active and has been updated but it is not finished, all other activities that are opened at the same time will be outdated, until the Activity is finished.

 

There are various methods to accomplish a successful synchronization of tokens. Some are explained below:

 

Using a Complex Gateway

You may use a Complex Gateway and an expression to filter each token and decide whether or not to continue with the process. For example, if you want to keep only the last token that reaches a point you can use the following configuration:

 

1. Add a Gateway to the model.

 

Synchronization_Each_Token_1

 

2. Add a Boolean attribute in your database where you can control when an instance of the multiple sub-process has finished.

 

Synchronization_Each_Token_2

 

3. Evaluate the following expression every time a token reaches the gateways, leaving only the last active. This way only the last token will be able to go through the flow, all other tokens will be discarded:

 

Synchronization_Each_Token_3

 

 <count(MyCollection)> = <count(MyCollection[Attrib=true])>;

 

You can customize your filter according to your business needs.

 

Using an Exclusive Gateway

You may use an Exclusive Gateway and an expression to filter each token and decide whether continue with the process or work through a different path with that process instance. For example, if you want to keep only the last token that reaches a certain point you can use the following configuration:

1. Add an Exclusive Gateway to the model.

 

Synchronization_Each_Token_4

 

2. Add a Boolean attribute in your database where you can control when an instance of the multiple sub-process has finished the sub-process.

 

Synchronization_Each_Token_2

 

3. Evaluate the following expression every time a token reaches the gateway. When the condition is not met, the token will be directed to the End event. When the last token meets the condition, the regular flow will continue.

 

Synchronization_Each_Token_5

 

<count(MyCollection)> = <count(MyCollection[Attrib=true])>;

 

You can customize your filter according to your business needs.

 

Using a Singleton activity

The Singleton property does not make an activity an element of synchronization itself, but might help depending on your business needs. The Singleton controls that only one instance of an Activity is active at a time. When a Singleton is used and an Activity is active (allocated to an end user), all other incoming tokens will be disregarded. When a Singleton is used and an Activity is NOT active, any incoming token will activate it, even if it was activated in the past.

 

If you are planning to use a singleton activity, bear in mind that when the activity is activated by a token, the tokens trying to start this activity will be terminated. But when the activity is completed and the token continues to the next activity, the other tokens in earlier activities can continue. Hence, this property is not a synchronization tool, but might be useful.

 

Synchronization_Each_Token_6