cancel
Showing results for 
Search instead for 
Did you mean: 

Script Task: Using external files as source

mjacobi
Champ in-the-making
Champ in-the-making
Hey,

in my currrent project i'm using the script task quite heavily. The script task is mainly used to config my processes, e.g. init process variables like e-mail recipients. I would like to store the script source on the file system, instead of the process definition. The reason therefore is, that even adding another recipient to a process variable (e.g."a@b.com" to "a@b.com,c@d.com"), I must deploy the process again.

Is there any (simple) way to do this?

Cheers
Malte
8 REPLIES 8

silvioneto
Champ in-the-making
Champ in-the-making
You can write a service task that load file contents into a process variable before your script task.

I've made something similiar, adding each recipient into a list and making the send message task multi instance…

mjacobi
Champ in-the-making
Champ in-the-making
That solution might work for some processes but not for all. In most processes / script tasks I do more complex stuff which I also want to put in an external file.
So, still no solution to my problem.

pmsevestre
Champ in-the-making
Champ in-the-making
Hi,

I'm also using a lot of script tasks in my apps. Since I foresaw much more script maintenance than changes in the processes themselves, I've decided early in the project to always run scripts from an external source (usually file system, but could be something else, like a JCR repository). In order to achieve this, I don't use "script tasks", but regular "service tasks" that always have a expression like this:

${scriptRunner.execute('scriptname',execution)}

In this expression, "scriptRunner" is a spring bean that loads a groovy script from a process-specific location (a folder named after the process definition key, in my case).

As soon as I have some time, I'll probably simplify this  using the new process parsing hooks (section 18 of the user manual). The idea would be to inject this expression at load time and adopt a convention that the script always has the same name of the task itself.



jbarrez
Star Contributor
Star Contributor
Sounds nice!

mjacobi
Champ in-the-making
Champ in-the-making
Thanks for the hint! I implemented a similar solution. I use a regular service task which implements JavaDelegate. Filename is specified as a class parameter and the execution context is bound to the groovyscriptengine.
Cheers.

sankarts
Champ in-the-making
Champ in-the-making
I would like to mention "external Groovy Script file" in my BPMN spec. Is it possible with Activiti?

To elaborate,
For the same script task in my workflow, different users would make use of different groovy scripts. For example, wanted to plug and play between 2 different external Groovy scripts for the same script task.

For example,  I  need to pick between external Groovy scripts "abc" and "xyz" on a case to case basis.

Instead of the round about ways like using Service Task and mentioning Groovy script file name like
<code>
${scriptRunner.execute('scriptname',execution)}
</code>

is it possible to mention the external Groovy script file name directly?

trademak
Star Contributor
Star Contributor
It's not supported in the current Activiti version, but it's certainly a feature that would make a lot of sense. Can you create a JIRA issue for this?

Best regards,

sankarts
Champ in-the-making
Champ in-the-making
The JIRA for the above discussed feature has been created.
<BBCode>
http://jira.codehaus.org/browse/ACT-2178
</BBCode>