2 Replies Latest reply on Jun 27, 2011 12:20 PM by brucecui

    How can a Service Task take integer variable via additional parameters?

    brucecui

      Here is the thing. I'm trying to test a self-defined service task. I have referred to the Chapter 13 in the user guide, and also the "JBPM5 Example - Human Task Forms with Variables - WorkItems" example. They worked fine.

       

      But I met problem when I tried to add an integer parameter in the task. Here are the things I have done:

      1. Defined a process with 4 String variables, and 1 Integer varible. Say aStr, bStr, cStr, dStr, and aInt.

      2. Defined a process form which is taking 4 String params. And aStr takes an integer value.

      3. Put a script task right after the start point. Parse aStr to aInt.

      4. Create a MyWorkDefinitions.wid file with the definition of my service task. 3 StringDataType, and 1 IntegerDataType parameters. Packs imported.

      5. Create a drools.rulebase.conf with MyWorkDefinitions.wid and WorkDefinitions.conf defined. (Here in the user guide there is a mistake).

       

      Until here, all things went fine. I can see the service task in a new editor window, and can see the parameters when I put one in the canvas. But the problem happened when I assign the variables to the parameters for the Integer one.

       

      I used format #{bStr} for the three String ones, they got accepted. But when I assigned #{aInt} to the Integer param, I got an error window.

       

      Here is a full message in the error log:

      (mxtInt is the actual variable name in my local example. aInt is just used in the upper description to make things clearer)

      2011-06-25_150959.jpg

       

      I'm new to both JBPM or Drools. I'm not sure whether I'm using this right. Please help me out here.

       

      Also I would like to know if there are any examples with output back to the process.

       

      Thanks in advace.

        • 1. Re: How can a Service Task take integer variable via additional parameters?
          krisverlaenen

          Hi,

           

          #{expression} only works for String parameters (as the result it produces is a String).  To map any other object to a Task parameter, you should use parameter mapping.  Parameter mapping allows you to copy the value of a process variable to the Task parameter.  For example, if you want to copy an Integer as a service parameter, define a parameter mapping that copies the value from a process variable to that service parameter.  You can use an on-entry/on-exit action on your service task (or a normal script task before the service task) to set the value of the Integer (in this case something like kcontext.setVariable("myIntVariable", new Integer(mxInt));

           

          The documentation on service input / output mapping has recently been extended, so it might be useful to reread the core engine: basics chapter and the human tasks chapter.

           

          Kris

          1 of 1 people found this helpful
          • 2. Re: How can a Service Task take integer variable via additional parameters?
            brucecui

            Thanks Kris, I used parameter instead. Just thought maybe this can be handled more smoothly.