问题
I have a service node which will be runned by a WorkItemHandler
.
At the end of executeWorkItem()
I do:
manager.completeWorkItem(workItem.getId(), resultMap);
How can I access from other places the resultMap
? Where is is held?
回答1:
What would you like to do with it? Where would you like to have access to it?
These results are passed to the process instance, so in the task that was used to start this service, you can map these results back into process variables, so they can be used in the rest of your process instance. For example, if your handler returns a result called "outcome" and you map that result parameter to a variable (using result mapping), you can then use this variable in scripts, or decisions, or map it as an input for a next service, etc.
Kris
回答2:
Just to elaborate on what Kris said (Kris & co, good job on 6.1 by the way)...
variable = ((WorkflowProcessInstance) processInstance).getVariable("variableName");
AND
((WorkflowProcessInstance) processInstance).setVariable("variableName", variable);
You need to cast the process instance you get back from the KieSession to type WorkflowProcessInstance in order to use the variable API.
See http://docs.jboss.org/jbpm/v6.1/userguide/jBPMBPMN2.html#d0e3371
回答3:
The easiest way to return results from a WorkItemHandler is mapping the HashMap containing the result keys into a previously defined process variable. You can do this in the "Result Mapping" view. The "Parameter" should be the key of the HashMap and the "Variable" is the desired process variable.
Here's an example.
WorkItemHandler:
Map<String, Object> results = new HashMap<String, Object>();
results.put("price", price);
wim.completeWorkItem(wi.getId(), results);
Now map the variables in the process view and your process definition (in TextEditor view) should look like this:
<dataOutputAssociation>
<sourceRef>_11_priceOutput</sourceRef>
<targetRef>myFlowPriceVariable</targetRef>
</dataOutputAssociation>
来源:https://stackoverflow.com/questions/9433776/jbpm-how-to-get-workitemhandler-results