jBPM How to get WorkItemHandler results

我只是一个虾纸丫 提交于 2020-01-05 14:11:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!