Quick Tip #009: Using Shared Variables in CIOS
What is a Shared Variable?In CIOS a shared variable is a variable that is "Shared" across all jobs for a given orchestration. By assigning a value to a shared variable in the right side of a map, that value will be accessible by all other jobs of that orchestration. Like all variables in CIOS shared variables are persisted in the event of power loss. Shared variables are only cleared when an orchestration is stopped via the WMC.
Run Orchestration Jobs SequentiallyWhen using a shared variable in an Orchestration, the option to run all jobs in a single instance is automatically checked. (In prior versions this option was called Run Orchestration Jobs Sequentially) It is not possible to read and write a variable simultaneously, therefore running jobs in a single instance will ensure the consistency of your shared variables because there is no simultaneous access.
Why Use Shared Variables?Shared variables are a powerful concept and enable numerous use cases, we'll highlight a few of the most common:
Sequence NumbersYou can use shared variables to generate sequence numbers for files, database records, etc. By simply creating a shared variable and incrementing it each time you need a new value you can easily generate sequence numbers.
Tip: It is important to make sure that you have a way to initialize your sequence number by reading the highest existing value, using a configuration property or by some other means because you may need to reset the sequence or advance it.