[JBoss jBPM] - Re: variable scope from a script
by tbeernot
| <process-definition>
| <start-state name='start'>
| <transition to='fork1'></transition>
| </start-state>
| <fork name='fork1'>
| <event type='node-enter'>
| <script>
| <expression>
| token.getProcessInstance().getContextInstance().setVariable("var","valueOfFork", token);"
| </expression>
| </script>
| </event>
| <transition to='state1' name='1'></transition> // the name is mandatory, otherwise there will be only one child.
| <transition to='state2' name='2'></transition> // the name is mandatory, otherwise there will be only one child.
| </fork>
| <state name='state1'>
| <event type='node-enter'>
| <script>
| <expression>
| token.getProcessInstance().getContextInstance().setVariable("var","valueOfState1", token);"
| </expression>
| </script>
| </event>
| <transition to='join1'></transition>
| </state>
| <state name='state2'>
| <event type='node-enter'>
| <script>
| <expression>
| token.getProcessInstance().getContextInstance().setVariable("var","valueOfState2", token);"
| </expression>
| </script>
| </event>
| <transition to='join1'></transition>
| </state>
| <join name='join1'>
| <transition to='end'></transition>
| </join>
| <end-state name='end'></end-state>
| </process-definition>"
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4191551#4191551
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4191551
17 years, 4 months
[JBoss jBPM] - Re: variable scope from a script
by tbeernot
Right. The methods are present, but they are not static. So:
| token.getProcessInstance().getContextInstance().setVariable("var","val", token)
|
But that does not give me the behavior I expect.
Again I have the simple fork/join flow (start state forking state1 and state2) and each of these states has a node-enter event containing a setVariable as described above, but each setting a different value.
| S
| |
| F val="a"
| / \
| val="b" s1 s2 val="c"
| \ /
| J
| |
| E
|
When the two childern have just forked, I iterate over ALL tokens in the workflow and do a
| lList.add( lContextInstance.getVariable("var", lToken) );
|
So at the end I would expect three different values in that list.
I do have three values, but they are all the same ("b"). Since I get 3x the value associated with a child, it must actually be 3x the value of the root token. Which again means that the setVariable is not actually setting the variable in the token context, but the root token context.
Am I missing something?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4191549#4191549
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4191549
17 years, 4 months
[JBoss jBPM] - Re: variable scope from a script
by tbeernot
"kukeltje" wrote : which userguide? Can you give me the url you used or tell me whether it is the one that comes with the 'suite'
It is the one that comes with the suite, but it's also the online version.
http://docs.jboss.com/jbpm/v3.2/userguide/html_single/
Paragraph 11.1.
However, I do see a difference now, 11.1 says:
The most basic operations are
|
| void ContextInstance.setVariable(String variableName, Object value);
| void ContextInstance.setVariable(String variableName, Object value, Token token);
| Object ContextInstance.getVariable(String variableName);
| Object ContextInstance.getVariable(String variableName, Token token);
And the script documentation says:
Also the following script-variables will be available :
|
| executionContext
| token
| node
| task
| taskInstance
So there is a ContextInstance and an ExecutionContext, that got me confused. What is this ContextInstance if not an ExecutionContext? Anyhow, I see the methods are statics on the ContextInstance, so this should work.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4191520#4191520
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4191520
17 years, 4 months