-
1. Re: How to get an object like kcontext to call setVariable("variable",value) for begin used by following tasks??
salaboy21 Oct 17, 2011 12:31 PM (in response to taitung.wilbert)Hi Guo-Guang,
Instead of setting a variable to the kcontext you should do the variable mapping in the workitem and the process will automatically copy that information to the process scope when the work item finish. The main idea of work item is that is an external execution from the process context, so having access to the kcontext is not usually a good practice.
Cheers
-
2. Re: How to get an object like kcontext to call setVariable("variable",value) for begin used by following tasks??
taitung.wilbert Oct 17, 2011 8:50 PM (in response to salaboy21)Hi Mauricio,
I did use variable mapping in the workitem handler.
That's why I can get the variable by using WorkItem.getVariable("").
You mention that externally accessing kcontext is not a good practice.
However, I think,in some situation, it is inevitable that some tasks(ex user task, script task, and etc)
depends on the outputs produced by WorkItemHandler.
Therefore, how do I can affect the variable value in WorkItemHandler,
or, is there any alternative of good practice to accomplish the process I want.
-
3. Re: How to get an object like kcontext to call setVariable("variable",value) for begin used by following tasks??
calca Oct 17, 2011 10:17 PM (in response to taitung.wilbert)1 of 1 people found this helpfulHey,
As well as you use parameter mapping, you have to use result mapping.
You will have to define for example "price" (1) variable in process.. when completing the work item, you pass a map<String, Object> with results of the work item. You will have to create the map, and put a variable "price"(or the name you want) (2), can pass the map to completeWorkItem method. Into the process, you have to map the result variable to the process variable. After executing the task, jbpm will copy the value of the result variable to the process instance variable.
And the same will apply to the subprocess. Into the parent process, you define how to map variables between process/subprocess.
Regards,
demian
-
4. Re: How to get an object like kcontext to call setVariable("variable",value) for begin used by following tasks??
taitung.wilbert Oct 18, 2011 12:08 AM (in response to calca)Thank you Demian.
Actually, I did use result mapping as well.
At last, I gave up the way using WorkItemHandler to call a web service and change a variable value.
I put all these codes in script task and it worked fine as well.
-
5. Re: How to get an object like kcontext to call setVariable("variable",value) for begin used by following tasks??
salaboy21 Oct 18, 2011 7:30 AM (in response to taitung.wilbert)1 of 1 people found this helpfulInput and output mappings are the way to go, obviously it will work if you put it inside a script task but I don't recommend that way at all. Using java snipets inside an xml file is definitely not a good approach. WorkItems will allows you to hook different implementations for different environments, like for example a MockService for your unit tests and the RealService for your production environments.
Cheers
-
6. Re: How to get an object like kcontext to call setVariable("variable",value) for begin used by following tasks??
taitung.wilbert Oct 18, 2011 8:45 AM (in response to salaboy21)thanks for remiding that.