5 Replies Latest reply on Aug 13, 2013 7:11 AM by Thomas Colditz

    getting process variables available in service task

    Thomas Colditz Newbie

      Hi all,

       

      i have a question about how to get my process variables available in a service task. I used the parameter mapping with {param=s}. "s"=process variable with a string in it.

      If i do an output of "s" in a scripttask it works as expected. But when i call workItem.getParameter("param") in service task its always null.

       

      I just go for Start->Script->Service->End.

       

      I'm glad for any suggestions about what I'm doing wrong.

       

      With kind regards,

       

      Tom

        • 1. Re: getting process variables available in service task
          micste Newbie

          I think that the mapping is wrong, try -> instead of =

          {param->s}

          If I use the editor in web designer to edit mappings a "is mapped to" is displayed as ->

          • 2. Re: getting process variables available in service task
            Maciej Swiderski Master

            it depends when and how you read them from work item? They will be set when the work item node is triggered and not before that.

             

            HTH

            • 3. Re: getting process variables available in service task
              Thomas Colditz Newbie

              Hi,

               

              thanks for your replies. I dont know how to change "=" to "->" since using the editor(eclipse-plugin) doesn't offer this ability. You can just type parameter and variable. And the xml(service task) looks like:

               

              <serviceTask id="_4" name="Service Task" operationRef="_4_ServiceOperation" implementation="Other" >
                   <ioSpecification>          <dataInput id="_4_param" name="Parameter" />
                        <dataOutput id="_4_result" name="Result" />
                        <inputSet>
                             <dataInputRefs>_4_param</dataInputRefs>
                        </inputSet>
                        <outputSet>
                             <dataOutputRefs>_4_result</dataOutputRefs>
                        </outputSet>
                   </ioSpecification>
              </serviceTask>
              

              So there is no mapping with my variable "s" visible here.    

               

              @Maciej: What do you mean with how/when i read from workItem? Here the sample code:

              public class SampleServiceTask implements WorkItemHandler{
                   public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
                        System.out.println(workItem.getParameter("param"));
                        workItemManager.completeWorkItem(workItem.getId(), null);
                  }
                  public void abortWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
                        System.out.println("Service task aborted.");
                  }
              }
              

              It makes no difference if I set "param" as precess variable on start or not ("s" ofc is set). I think I'm doing something very basic wrong atm.


              Greeting,

              Tom

              • 4. Re: getting process variables available in service task
                Maciej Swiderski Master

                alright, now I can see what's wrong. You have single data input defined for your service task and it's called Parameter so if you like to get it's value inside the work item handler you need to use exactly the name defined there:

                 

                System.out.println(workItem.getParameter("Parameter"));

                 

                and that should give you the expected value.

                 

                HTH

                • 5. Re: getting process variables available in service task
                  Thomas Colditz Newbie

                  Thank you very much. So it is.

                   

                  Kind regards,

                   

                  Tom