JBPM 5.4 process variables - drools

I am new to Jbpm 5.4. I want to set a process variable after completing one Human task. I know we can add process variables at start up using a map. Can any one tell me how set process variable in the middle of the process please???

Result mapping & data associations. Like any other type of task.
See
https://docs.jboss.org/jbpm/v5.4/userguide/ch.human-tasks.html#d0e4970
Result mapping: Allows copying the value of result parameters of the
human task to a process variable. Upon completion of the human task,
the values will be copied. A human task has a result variable "Result"
that contains the data returned by the human actor. The variable
"ActorId" contains the id of the actor that actually executed the
task.
also
https://github.com/droolsjbpm/jbpm/blob/master/jbpm-bpmn2/src/test/resources/BPMN2-DataOutputAssociations.bpmn2
for an example

Related

Anylogic how create new agent and assign properties?

Anylogic: This should be simple but I just cannot find it in the help files..
On creating a new agent instance, we know there are four parameters and what they are, but not in what order they were defined. Lets say parameters are "type_of_car" (String), "number_of_pax" (Integer), "automatic" (boolean), "fuel_capacity" (double). Now when calling: new myagenttype("ford", 5, false, 55) the agent gets created as a ford with 55 pax, manual and 5 liter fuel capacity - which is all wrong. (it seems the definition order of the parameters in the agent definition are in a different order)
How do we include the parameter name (or definition) when we call new agenttype() to avoid this problem, ensuring the right value gets assigned to the right parameter?
The problem originates because of a bug in Anylogic's logic in triggering functions. We have a Split which creates a new agent and assigns the agent properties on the "On exit copy" - event, however what Anylogic does is it creates the agent, forward it to the next logical block (a decision node), then execute the code of the decision - all wrong now for the agent's properties are undefined - and only then executes the "On exit copy" event which assigns the agent's properties. Very frustrating.
This is actually not a bug, this is defined in the simulation experiment properties, in the randomness section, with the "selection mode for simultaneous events" property. The default is LIFO, but if you want the opposite behavior in your case you should use FIFO... I always use LIFO too, and in these cases, sometimes I might use a 1milisecond auxiliary delay between the split and the next block in order to control the order manually... if you do that, you will solver your problem in fact... just use a 0.001 miliseconds delay after your split
Now from your Agent Type problem, the arguments for your class constructor should be written in order, and the only way to know the correct order is by using the autocomplete feature when you write new agenttype()... the autocomplete will tell you the order in which you should write your constructor arguments.

How do I store a process variable to a global variable in KIE Workbench? (jBPM 7)

I have a global Integer variable RANDOM_NUMBER
I just want to store the response from a service that returns a random number into that global variable. How do I do that in the workbench?
So basically RANDOM_NUMBER = result
Business process:
Variables:
Service Data I/O:
I think, but I can't say I tested carefully, that global variables are shared between processes or process instances and process data is available to a specific process instance.
EDIT: So you can save the result of a workitem into a process variable but you have to use code to access the global variables. See section 8.6.1. Variables of the documentation.
The issue will be that "result" isn't available as a variable in the context of the exit script. It's an output parameter of the workitem. So, in order to get the result of the workitem into a variable that then can be copied into a global variable create a process variable (in your case result though I'm not a fan of the duplicate name) and assign result to that, which it looks like you did.
So probably the script on the exit script of the REST workitem should be.
kcontext.getKieRuntime().setGlobal("RANDOM_NUMBER", Integer.parseInt(result.trim()));

Using agent parameters from main to different agent?

For a project I'm trying to select the right output if a parameter of the created agent is true. The agent is created in the main but goes into a different agent for the selection of the output. If I use a select in the main and use the statement for the parameter as condition it works fine. Whenever it enters the agent and I use the same statement it gives an error (Description: product1 cannot be resolved or is not a field. Location: testCase5/Transport/selectOutput - SelectOutput).
I tried using different conditions like main.agent.product1 . Can't seem to solve the issue. I know that it has to do something with declaration probably but I'm clueless at the moment.
//for the condition that works if I put the selectOutput in the main
agent.product1
//for the condition in the agent I tried the same but didn't work. also tried
main.agent.product1 // Gives the same error but for (Description: agentcannot be resolved or is not a field.)
(Main)agent.product1
//And a few more
In AnyLogic each block of a project flow (regardless if from the process modeling library, the pedestrian library or another) has the type of Agent that is flowing through it defined in its properties. You can find this setting as Agent type in the block's properties under Advanced.
If you fail to set this correctly (meaning this setting equals the type of Agents you let flow through it), it will still flow through, BUT: you cannot access the specific properties of the Agent type.
That said, usually you do not even have to think about, because AnyLogic has an automatism there: The first block of your process flow, typically a Source-block or a Enter-block is the only block where you have to make the correct setting, all attached blocks get it then automatically!
However this does not work when:
You have separate flows (eg. you leave one flow through an Exit-block and enter another by an Enter). You'll manually have to put the correct setting also for the first block of the second process flow.
Your process flow is continued inside of another Agent/Custom Block, as in your example. AnyLogic doesnt realize the process flow inside your custom block is logically connected to the outside process flow in main. You have to specifiy manually again the Agent type flowing through in the first block of your process inside your Custom Block.

How to change process variable value through remote rest api call for current human task in jbpm 6.5.0Final

I have a many human task. After start the process i want to update some process variable value with rest API call that's relates to current task. If anyone knows how to do that commend bellow.
I try with /execute this is only start the task then how to update the process variable for already started process instance?
Based on the documentation
Here is how to do update the process variable. However, this will update an entire process rather than only that specific task.
server/containers/{id}/processes/instances/{pInstanceId}/variables - POST
If you want to update process variable from a task, you should do it during task completion. However, this requires you to have output variables from that task. Otherwise, it won't take any effect.
server/containers/{id}/tasks/{tInstanceId}/states/completed - PUT
Anyway, the full documentation of rest can be viewed in
{localhost}:{port}/kie-server/docs

Talend: how to fork the output of a parent job and call either of child job based on some condition

I am learning Talend. I have a scenario where I have to apply if else if condition to the output from the parent job and based on the outcome, call either of the child jobs. I have thought of few options such as using global variables or context variables. Is it possible to configure the child jobs to listen to the global/context variable change and run if the condition match? I tried looking to configure this, but failed to understand where can I do these configurations.
I even tried taking the output from the parent job component's into a tjavarow where I can write java code with if else if conditions. I was thinking to explicitly call the sub jobs from the if else branching, but I am not able to make any headway. Can someone please direct me through the right approach? Any new approach is also welcomed.
NOTE: We are using free version of Talend.
If I understand correctly, this can be achieved using "Run If" triggers, like this:
Inside tJava, you can write some logic to calculate your variables.
On the If trigger, you write a condition that determines whether or not the component after it is run.
In my example, I'm not actually making use of what's inside tJava, I'm just getting the number of lines output by tLogRow, so it can be left out and the "Run If" triggers connected directly to tLogRow.