Discussion:
[jboss-user] [jBPM] - How to get parameters in script action
martin steve
2013-01-19 03:57:46 UTC
Permalink
martin steve [https://community.jboss.org/people/martin_2013] created the discussion

"How to get parameters in script action"

To view the discussion, visit: https://community.jboss.org/message/792880#792880

--------------------------------------------------------------
Hello everybody.I have a question, then need your help.

I start a process by session and set a map of parameters.The name of a parameter is "person". As follows:

KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kBuilder.add(ResourceFactory.newClassPathResource("hello.bpmn"),
                ResourceType.BPMN2);
KnowledgeBase kBase = kBuilder.newKnowledgeBase();
StatefulKnowledgeSession kSession = kBase.newStatefulKnowledgeSession();
Map<String, Object> params = new HashMap<String, Object>();   
Person person = new Person();
person.setName("martin");
params.put("person", person);
ProcessInstance pInstance = kSession.startProcess("com.sample.hello", params);

then I think print the name of person in a script action.Code as follows:

System.out.println(person.getName());

I run my codes and then get a exception:

[main] ERROR builder.impl.KnowledgeBuilderImpl.newKnowledgeBase  - Process Compilation error : ***@79024994
     defaultPackage/Process_defaultPackage_Sample_Process_4419562b234b4de3b32f940de6602c9f.java (11:468) : person cannot be resolved

Exception in thread "main" java.lang.IllegalArgumentException: Could not parse knowledge.
    at org.drools.builder.impl.KnowledgeBuilderImpl.newKnowledgeBase(KnowledgeBuilderImpl.java:79)
    at com.sample.JBPMTest.main(JBPMTest.java:23)

How to get parameters in script action?
Thank you!
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/792880#792880]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-01-21 09:21:47 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: How to get parameters in script action"

To view the discussion, visit: https://community.jboss.org/message/793187#793187

--------------------------------------------------------------
the way you do it is the right way only thing that comes to my mind seeing this is that Person class is either not available on class path or it is not declared as type (using FQN). Check https://github.com/droolsjbpm/jbpm/blob/master/jbpm-bpmn2/src/test/resources/BPMN2-BusinessRuleTaskWithDataInputs.bpmn2 here as it can be done.

HTH
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/793187#793187]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
martin steve
2013-01-21 13:56:23 UTC
Permalink
martin steve [https://community.jboss.org/people/martin_2013] created the discussion

"Re: How to get parameters in script action"

To view the discussion, visit: https://community.jboss.org/message/793249#793249

--------------------------------------------------------------
Thank you for your answer, Swiderski.
I read the document of jbpm5.4 and find the following paragraphs
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/793249#793249]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-01-21 14:25:59 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: How to get parameters in script action"

To view the discussion, visit: https://community.jboss.org/message/793256#793256

--------------------------------------------------------------
as far as I know kcontext is only available in process scope so if you would use java based condition then you could directly take advantage of kcontext variable but within rules you need to insert process instance into the ksession before you can make use of it.

HTH
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/793256#793256]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
martin steve
2013-01-23 02:05:48 UTC
Permalink
martin steve [https://community.jboss.org/people/martin_2013] created the discussion

"Re: How to get parameters in script action"

To view the discussion, visit: https://community.jboss.org/message/793634#793634

--------------------------------------------------------------
Thank you.
I try to directly use  variable kcontext  in a script action.It's a success.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/793634#793634]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Loading...