When using variables, either global or scope, in a BPEL process you have to make sure you initialize them with a value before use or an exception will be thrown. You can do this easily with an <assign> tag during the execution of the process. Yet, what if you want to use a global variable for the life-span of the process and do not want to reassign it on every <receive> or <pick> that starts the sequence?

As of BPEL 2.0 you can initialize your variables with an inline from-spec in the XML. What??? This is really quite simple. In the variable declaration sections that could look like this:

<variables>
       <variable name="PostCount" type="xsd:long"/>
</variables>

You just need to modify it with a from-spec like so:

<variables>
       <variable name="PostCount" type="xsd:long">
             <from><literal>1</literal></from>
        </variable>
</variables>

The the <assign>, <copy> and <to> tags are implied and do not need to be set.

This makes it very easy to initialize a variable at any scope when it is defined so you do not hit the uninitiated error when running your BPEL process. This also allows you to have global variables that can be used during the entire life-span of the process without having to reset it every <receive> or <pick> event.

NOTE: Currently the Sun BPEL SE for OpenESB does not support this inline variable initialization which makes using global variables for tracking quite pointless. Hopefully the team will implement this as it is standard BPEL 2.0.