cancel
Showing results for 
Search instead for 
Did you mean: 

JavaScript error in Script Task

arno1
Champ in-the-making
Champ in-the-making
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?
7 REPLIES 7

frederikherema1
Star Contributor
Star Contributor
The 'document' is only available on client-side JavaScript, in activiti JavaScript is purely used as language…

arno1
Champ in-the-making
Champ in-the-making
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?

frederikherema1
Star Contributor
Star Contributor
Check out activiti-engine-examples/src/main/process/org/activiti/examples/bpmn/scripttask/ScriptTaskTest.testSetScriptResultToProcessVariable.bpmn20.xml:

<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.

arno1
Champ in-the-making
Champ in-the-making
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.

arno1
Champ in-the-making
Champ in-the-making
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 😉

sarra1
Champ in-the-making
Champ in-the-making
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

trademak
Star Contributor
Star Contributor
Is ProduitD always 2 then?

Best regards,