IBM BPM, V8.0.1, All platforms > Create processes in IBM Process Designer > Modeling processes > Business objects and variables > Declaring and passing variables

How variables are passed in Process Designer

Using variables, business data in Process Designer is passed between processes and linked processes, between processes and services, and between services and services.

Variables capture business data. If the business data is a simple type (for example, a String) then the variable contains a value of the business data. If the business data is a complex type then the variable is a reference to an object containing multiple values.

Variables can be passed by reference or by value, as described in the following table.

How variables are passed
From To Type Pass by
Business process definition (BPD) activity Service Simple Value
BPD activity Service Complex Value (the BPD and Service have separate copies of the business object)
BPD activity Linked BPD Simple Value
BPM activity Linked BPD Complex Reference to the same business object
Service Nested service Simple Value
Service Nested service Complex Reference to the same business object

Variables passed by reference

Most data interactions in a process are passed by reference (from BPD to BPD or from service to service). Therefore, most of the time the same object is passed from location to location. Also, changes to that object happen at all levels.

Variables passed by value

Variables between BPDs and services are passed by value. When a variable is passed by value from a BPD to an underlying service, the service that changes the variable passes the changed complex variables back to the BPD as output variables.

Variables that are shared objects

If a variable is defined as a shared object, its values are refreshed from the data store before use.

For example, a shared object is passed by value from a BPD to two different services. The BPD and services will each contain a separate copy of the business object.

When the first service completes, the values of the shared object will automatically be persisted to the data store. When the second service starts, the shared object values will be automatically loaded from the data store.

So even though the BPD and two services reference separate objects, the values of these objects are updated by the data store. This allows the running services to operate on current data. See Create business objects for information on shared objects.

BPDs and services have references to their variables. When complex variables are passed from a BPD to a service, a deep copy of the variable is transferred from the BPD space to the service space, and the service gets a reference to the copy. Similarly, when a complex variable is passed from the service to a BPD, a deep copy of the variable is transferred from the service space to the BPD space, and the BPD gets a reference to the copy.

When the service changes the values of the existing complex variable, the changed values are passed back to the BPD by replacing the entire complex variable with a deep copy from the service. If the replaced variable was originally passed by value from an outer BPD, the inner and outer BPDs no longer access the same variable. Therefore, changes made to the inner BPD are not reflected in the outer BPD.

Example

An outer BPD has a reference, tw.local.pair, that points to a NameValuePair object, NVP1. The outer BPD passes its .pair reference to an inner BPD:
Outer BPD -> NVP1
Inner BPD -> NVP1
Changes to either BPD affect the other BPD.

The inner BPD passes the .pair to a service. A copy of NVP1 is made, NVP2, and a reference of the copy is passed to the service.
Outer BPD -> NVP1
Inner BPD -> NVP1
Service -> NVP2

The service exits and outputs the .pair, mapped back to the variable of the inner BPD .pair. A copy of NVP2 is created, NVP3, and a reference is passed back to the inner BPD.
Outer BPD -> NVP1
Inner BPD -> NVP3
Changes made to NVP3 are not reflected in NVP1.

If you want a service to modify a top-level variable in a BPD, use an embedded JavaScript to store the service result in a temporary variable and copy its members to the original variable. The parent BPD is not updated until the child BPD has finished.


Recommended guidelines

Because of how Process Designer handles variables, follow these guidelines:

Declaring and passing variables