0
votes

Here's my code that starts a process:

StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

Map<String, Object> params = new HashMap<String, Object>();
params.put("doctorsDecision", "L1");
ksession.startProcess("MyProcess", params);

And here's how I expect this variable to be available in MyProcess. This is the Action of one of my script tasks in MyProcess:

System.out.println("doctorsDecision: "+doctorsDecision);

Is this the right way to access external variables from within a process?

P.S.

When I run my application, the process definition is never added to knowledge base because jBPM doesn't seem to recognize doctorsDecision variable. How can I tell jBPM that this variable is external and it's value will be provided on runtime?

2

2 Answers

0
votes

Can you describe a little bit better your process? Do you have just the start event and then the script task with that print out? Did you define the input variables from the process? Because you should add to the process definition that variable that will be received from the out side world when you start the process.

Can you give us more context? What do you mean with " the process definition is never added to knowledge base " if you can start the process, that means that the process was added to the knowledge base.. if not the startProcess("MyProcess", params) will fail. Can you show the output of the execution?

Using the KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession); before starting your process will show you in the console the internal activity of the process engine.

Hope it helps.. Cheers

0
votes

I am a beginner of JBPM, and I meet the same question when I start to use JBPM. Try to add the data object in your proess name is doctorsDecision and type is String

the result is

<process>
...
...
<dataObject id="doctorsDecision" name="doctorsDecision" itemSubjectRef="ItemDefinition_1"/>
</process>

<itemDefinition id="ItemDefinition_1" structureRef="String"/>

and it works for me.