Using globals in a script task and understanding global behavior

799 views
Skip to first unread message

Nicholas McRae

unread,
Jan 14, 2015, 11:38:36 AM1/14/15
to jbpm-...@googlegroups.com
I'm now investigating the use of global variables for my previous problem:

- defining global variables with important project information, which can be accessed and queried from any running process

I wonder:
- how I can access and manipulate a global variable from a process script task
(I've been searching for syntax but none of it seems to work at this time)

In terms of behavior I wonder:
- are globals scoped within each project instance, or are they accessible from any project instance?

In other words: If I start the highest level process of a project twice, and have two instances of that process, do they each have their own version of a global, or is the global defined for each?

Mauricio Salatino

unread,
Jan 14, 2015, 11:50:25 AM1/14/15
to Nicholas McRae, jbpm-...@googlegroups.com
I would recommend to use/create a service to store that information instead of a global variable. And then just use normal WorkItemHandlers to access and modify/update that data. 

 

--
You received this message because you are subscribed to the Google Groups "jBPM Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-usage+...@googlegroups.com.
To post to this group, send email to jbpm-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jbpm-usage/e1d04ad9-63dd-4c17-b3b5-9482597e0d34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
 - MyJourney @ http://salaboy.com
 - Co-Founder @ http://www.jugargentina.org
 - Co-Founder @ http://www.jbug.com.ar
 
 - Salatino "Salaboy" Mauricio -

Mauricio Salatino

unread,
Jan 14, 2015, 11:50:43 AM1/14/15
to Nicholas McRae, jbpm-...@googlegroups.com
my suggestion will be also to stay away for script tasks :)

Nicholas McRae

unread,
Jan 14, 2015, 12:18:55 PM1/14/15
to jbpm-...@googlegroups.com, nicholas...@gmail.com
Thanks for your reply.

Do you happen to know the answers to the original questions? If I wanted to implement a global variable solution?

Mauricio Salatino

unread,
Jan 14, 2015, 12:44:58 PM1/14/15
to Nicholas McRae, jbpm-...@googlegroups.com
Well it depends on how you scope your Ksession creation. In jBPM 6 we have different strategies and based on the strategy that you choose the scope will be different. 
For example if you use the strategy called Per Process Instance, the scope of your global variable will be create for each process instance that you create. If you use the Singleton Strategy
the global variable will be shared between all the process instances started in that session.

HTH


For more options, visit https://groups.google.com/d/optout.

Nicholas McRae

unread,
Jan 14, 2015, 12:48:56 PM1/14/15
to jbpm-...@googlegroups.com, nicholas...@gmail.com
Thanks so much for the explanation.

Do you happen to know the syntax to reference a global within processes while using the workbench? Have tried the usual suspects while searching over the internet and I don't seem to be able to access a global.

Nicholas McRae

unread,
Jan 14, 2015, 2:26:16 PM1/14/15
to jbpm-...@googlegroups.com, nicholas...@gmail.com
Turns out some of the syntax that I found on Stack actually did work, but I was running into some other errors. The syntax I used to access the global in a script task was:

kcontext.getVariable("counter");
Reply all
Reply to author
Forward
0 new messages