cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript Scripttask help

arschloch1989
Champ in-the-making
Champ in-the-making
Hi,

I've created a script task in a subprocess, but value is null after i declare it, how to I declare a value in the script that can be used in a exclusive gateway so that I can proceed through my workflow.

when i run the process and get to this part(script task) I get an error saying no outgoing sequence flow of… when i try to complete task of choosing my phone model.

Any help would be greatly appreciated

snippet of the code:

<userTask id="selectSonyEricssonModel" name="Select Sony Ericsson Model" activiti:candidateGroups="Employee">
        <documentation>Please select the Sony Ericsson Model you would like from the list below.</documentation>
        <extensionElements>
        <activiti:formProperty id="sonyEricssonModel" name="Sony Ericsson Model:" type="enum" required="true">
          <activiti:value id="sonyEriccsonModel1" name="Sony Ericsson X10"></activiti:value>
          <activiti:value id="sonyEriccsonModel2" name="Sony Ericsson X10 Mini Pro"></activiti:value>
          <activiti:value id="sonyEriccsonModel3" name="Sony Ericsson X8"></activiti:value>
          <activiti:value id="sonyEriccsonModel4" name="Sony Ericsson Arc"></activiti:value>
          <activiti:value id="sonyEriccsonModel5" name="Sony Ericsson Neo"></activiti:value>
        </activiti:formProperty>
        </extensionElements>
      </userTask>
     
      <sequenceFlow id="flow8" name="" sourceRef="selectSonyEricssonModel" targetRef="phonePrice"></sequenceFlow>

<scriptTask id="phonePrice" name="Phone Price" scriptFormat="javascript" activiti:resultVariable="myVar">
        <script>
        <![CDATA[
             var myVar = 250;   
           ]]>
      </script>
      </scriptTask>
       
      <sequenceFlow id="flow9" name="" sourceRef="phonePrice" targetRef="endSelectPhoneProcess"></sequenceFlow>
     
      <endEvent id="endSelectPhoneProcess" name="End Select Phone Process"></endEvent>
        
    </subProcess>
    
    <sequenceFlow id="flow13" name="" sourceRef="selectPhoneProcess" targetRef="approveRequestDecision"></sequenceFlow>
   
    <exclusiveGateway id="approveRequestDecision" name="Approve Request Decision"></exclusiveGateway>
      
    <sequenceFlow id="flow14" name="Request Rejected" sourceRef="approveRequestDecision" targetRef="selectPhoneProcess">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${myVar > 350 }]]></conditionExpression>
    </sequenceFlow>
      
    <sequenceFlow id="flow15" name="Request Approved" sourceRef="approveRequestDecision" targetRef="viewRequest">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${myVar <= 350}]]></conditionExpression>
    </sequenceFlow>
   
   
    <userTask id="viewRequest" name="View Request" activiti:candidateGroups="Managers">
    <documentation textFormat="text/plain">${myVar}</documentation>
    </userTask>
5 REPLIES 5

meyerd
Champ on-the-rise
Champ on-the-rise
Hi arschloch1989,

Do you want to set a process variable in a script task?

You can use the custom variable "execution":
<script>
    def scriptVar = "test123"
    execution.setVariable("myVar", scriptVar)
</script>

Does this help?

arschloch1989
Champ in-the-making
Champ in-the-making
no that didn't work, I now get an error saying "problem evaluating script":

my script task is:
<scriptTask id="phonePrice" name="Phone Price" scriptFormat="javascript" activiti:resultVariable="myVar">
        <script>
        def scriptVar = 123;
        execution.setVariable("myVar", scriptVar);
  </script>
      </scriptTask>

also tried and got the same error:
<scriptTask id="phonePrice" name="Phone Price" scriptFormat="javascript" activiti:resultVariable="myVar">
        <script>
        def var scriptVar = 123;
        execution.setVariable("myVar", scriptVar);
  </script>
      </scriptTask>



I want to set a variable/value in the script task that I can use in my workflow.
i.e. a variable myVar set to 123, and when I use an exclusive gateway I want to to say if > 350 end process, <= 350 move on do the next task, where it will display the myVar value in the documentation

arschloch1989
Champ in-the-making
Champ in-the-making
I got it working, tried something else and it worked, it was a error in the exclusive gateway that I only after seeing that was causing the error.

code below from script task on, incase anyone else has the same problem in the future (Thanks for your help meyerd):


       <scriptTask id="phonePrice" name="Phone Price" scriptFormat="javascript">
        <script>
          <![CDATA[var myVar="123";]]>
        </script>
      </scriptTask>
       
      <sequenceFlow id="flow9" name="" sourceRef="phonePrice" targetRef="endSelectPhoneProcess"></sequenceFlow>
     
      <endEvent id="endSelectPhoneProcess" name="End Select Phone Process"></endEvent>
        
    </subProcess>
    
    <sequenceFlow id="flow13" name="" sourceRef="selectPhoneProcess" targetRef="approveRequestDecision"></sequenceFlow>
   
    <exclusiveGateway id="approveRequestDecision" name="Approve Request Decision"></exclusiveGateway>
      
    <sequenceFlow id="flow14" name="Request Rejected" sourceRef="approveRequestDecision" targetRef="selectPhoneProcess">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${myVar > 350}]]></conditionExpression>
    </sequenceFlow>
      
    <sequenceFlow id="flow15" name="Request Approved" sourceRef="approveRequestDecision" targetRef="viewRequest">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${myVar <= 350}]]></conditionExpression>
    </sequenceFlow>
   
    <userTask id="viewRequest" name="View Request" activiti:candidateGroups="Managers">
    <documentation>
    Phone: ${phoneManufacturer}-${phoneModel},
    Phone Price: €${myVar}
    </documentation>
    </userTask>

guru_nayak
Champ in-the-making
Champ in-the-making
Facing the very same problem passing variables from external source to workflow context

<scriptTask id="scriptTask" scriptFormat="LiferayJavaScript">
   <script>
        def var person = (Long) workflowContext.get(productUtil.getPerson(PK_ID));
   </script>
</scriptTask>

but in our case the person variable is not available outside the workflow. We are still trying out various alternatives to resolve this issue.

rockstrom
Champ in-the-making
Champ in-the-making
Actually, I read the activiti in action book and set the [form key] in start event based on a section in the following chapter:
activiti_in_action.pdf -> appendix B "BPMN 2.0 supported elements in activiti" -> None start event page 39

It says that "The none start event is the simplest start event element that can be started using the Activiti API" …
…..
and its properties are activiti:formKey and activiti:initiator

Please take a look:
http://imageshack.us/scaled/landing/534/cnu6.png

For this reason I used the form key in start event.

thanks for your help.