JavaScript error in Script Task
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2011 03:46 AM
Hello,
I'd like to design a very simple hello world script task using Activiti by using JavaScript as language. Therefore I defined a really simple example in the Eclipse modeling plugin and wrote a simple jscript code. Therefore I deployed the process definition and startet an instance. But when I want to give an output by using JavaScript an error occurs. Does somebody know how it can be made that the output of my code (see screenshot) can be viewed?
I'd like to design a very simple hello world script task using Activiti by using JavaScript as language. Therefore I defined a really simple example in the Eclipse modeling plugin and wrote a simple jscript code. Therefore I deployed the process definition and startet an instance. But when I want to give an output by using JavaScript an error occurs. Does somebody know how it can be made that the output of my code (see screenshot) can be viewed?
Labels:
- Labels:
-
Archive
error_jscript.png
8 KB
code_jscript.png
17 KB
7 REPLIES 7
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2011 03:59 AM
The 'document' is only available on client-side JavaScript, in activiti JavaScript is purely used as language…
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2011 04:22 AM
Okay, but how can I use a variable in the script for showing it in a certain step of the process? For example as I stated above, I'd like to calculate someting and I'd like to have the string "The result is 9" as a process variable, so that it can be used in anther task for example like the input of a form in a user task. There I can use for example the variable ${employee} if I have a input element in my form called employee.
The only thing I'd like to know is how to use (and show) the result or the content of a certain script variable in another task for example a user task.
I've also tried out the in the user guide given example with groovy. It doesn't work either.
Here's the groovy sript code i've insertet into the script field of my script task (eclipse):
def scriptVar = "Hello with groovy from the Script Task"
execution.setVariable("myVar", scriptVar)
Then the next task is a user task where i'd like to do an output of scriptVar in the documentation field:
${scriptVar}
Then an error occurs which tells me that the used property (apparently the one which is stated in the juel expression above) is unknown!
So how can I handle that?
The only thing I'd like to know is how to use (and show) the result or the content of a certain script variable in another task for example a user task.
I've also tried out the in the user guide given example with groovy. It doesn't work either.
Here's the groovy sript code i've insertet into the script field of my script task (eclipse):
def scriptVar = "Hello with groovy from the Script Task"
execution.setVariable("myVar", scriptVar)
Then the next task is a user task where i'd like to do an output of scriptVar in the documentation field:
${scriptVar}
Then an error occurs which tells me that the used property (apparently the one which is stated in the juel expression above) is unknown!
So how can I handle that?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2011 04:32 AM
Check out activiti-engine-examples/src/main/process/org/activiti/examples/bpmn/scripttask/ScriptTaskTest.testSetScriptResultToProcessVariable.bpmn20.xml:
Userguide
<scriptTask id="theScriptTaskWithNewProcessVariableName" scriptFormat="juel" activiti:resultVariable="newProcessVariableName">
<script>#{echo}</script>
</scriptTask>
Userguide
Script results
The return value of a script task can be assigned to an already existing or to a new process variable by specifying the process variable name as a literal value for the 'activiti:resultVariable' attribute of a script task definition. Any existing value for a specific process variable will be overwritten by the result value of the script execution. When not specifying a result variable name, the script result value gets ignored.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2011 07:20 AM
Yes, I've already read this but I do not understand it. Is it possible to give a concrete example?
The starting of a process by using the file you recommended throws errors.
A very concrete example would be very helpful. Thanks.
The starting of a process by using the file you recommended throws errors.
A very concrete example would be very helpful. Thanks.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2011 07:37 AM
I found it out 🙂
for everyone who's interested in how to get a JavaScript return value:
here's the section of the xml file:
<scriptTask id="scripttask2" name="Script Hello" scriptFormat="javascript" activiti:resultVariable="myVar">
<script>
var myVar="hey";
</script>
</scriptTask>
and if you call that for example in a next step in a user task you can do it by using juel expressions:
<userTask id="usertask1" name="User Task" activiti:assignee="kermit">
<documentation textFormat="text/plain">${myVar}</documentation>
</userTask>
the blue marked sections have to be the same 😉
for everyone who's interested in how to get a JavaScript return value:
here's the section of the xml file:
<scriptTask id="scripttask2" name="Script Hello" scriptFormat="javascript" activiti:resultVariable="myVar">
<script>
var myVar="hey";
</script>
</scriptTask>
and if you call that for example in a next step in a user task you can do it by using juel expressions:
<userTask id="usertask1" name="User Task" activiti:assignee="kermit">
<documentation textFormat="text/plain">${myVar}</documentation>
</userTask>
the blue marked sections have to be the same 😉
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2013 08:27 AM
In my script I need to have a condition but always JavaScript return value in the last condition
var myVar="";
if(Produit==1)
{
myVar="compte1";
}
if(ProduitD==2){
myVar="compte2";
}
how can I do ? help please
var myVar="";
if(Produit==1)
{
myVar="compte1";
}
if(ProduitD==2){
myVar="compte2";
}
how can I do ? help please

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2013 09:56 AM
Is ProduitD always 2 then?
Best regards,
Best regards,
