cancel
Showing results for 
Search instead for 
Did you mean: 

Process instance variable to drive Service Task

rdewall
Champ in-the-making
Champ in-the-making
Generally these are questions to help me understand process instance variables and their usage within a service task.

If I understand correctly, the service task instance is essentially a singleton and is shared among all process instances.  When the service class task is instantiated, its field injection is permanent to that instance.

Given that, if I wish to drive a service task conditionally based upon process instance variables, can that be done?  For example, serviceTaskA, when executed by processInstanceA with variable X=1 should perform one way, while serviceTaskA, when executed by processInstanceA with variable X=2 should perform another.

The documentation alludes to this in the statement:

"To inject values that are dynamically resolved at runtime, expressions can be used."

It then goes on to reiterate the singleton nature of the class:

"Since the Java class instance is reused, the injection only happens once, when the serviceTask is called the first time. When the fields are altered by your code, the values won't be re-injected so you should treat them as immutable and don't make any changes to them."

What am I missing, or is my use-case not achievable in this fashion?
2 REPLIES 2

mproch
Champ in-the-making
Champ in-the-making
Hi,
when you implement ServiceTask by implementing JavaDelegate, you have access to process instance variables by DelegateExecution object:

public void execute(DelegateExecution execution) throws Exception {
    String var = (String) execution.getVariable("input");
    var = var.toUpperCase();
    execution.setVariable("input", var);
  }
- it's in user guide…

Is this what you're looking for?

rdewall
Champ in-the-making
Champ in-the-making
I think so yes.  I was confusing field injection with with process instance variables.  Thanks.