0 Replies Latest reply on Sep 7, 2015 7:20 PM by Severin Sobetzko

    Setting and manipulating a globally accessible variable in ScriptTasks

    Severin Sobetzko Newbie

      Hello,

       

      For my Workflow I would like to set a loop that runs X number of times and then moves on to another flow defined by an exclusive Gateway. I got this to work in other engines by defining a simple Integer variable in one script task and then increasing it by one everytime it passes my "Increase counter" Script task. But now I've run into a wall since I can't seem to access the variable and I'm stumped on why I get the error that "counter caanot be resolved to a variable".

       

      In my "Set Counter" Script task I'm using this Script in Java:


      <bpmn2:script>
      <![CDATA[

        kcontext.getKnowledgeRuntime().setVariable("counter", "Integer");]]

      </bpmn2:script>

       

      And in my "Increase Counter" Script Task I'm doing this :


      <bpmn2:script>
      <![CDATA[

      Integer temp = kcontext.getVariable("counter");

      temp += 1;

      kcontext.setVariable("counter", temp);

      </bpmn2:script>


      The serverlog says "the method must return a result of type Object". I already tried casting the value but the problem stays the same.

      Maybe you could get me on the right track? I have the nagging feeling i'm just missing something really basic here.

       

      Thank you for your help in advance,

      Severin