Discussion:
[jboss-user] [jBPM] - getting process variables available in service task
Thomas Colditz
2013-08-12 08:06:03 UTC
Permalink
Thomas Colditz [https://community.jboss.org/people/fellowtom] created the discussion

"getting process variables available in service task"

To view the discussion, visit: https://community.jboss.org/message/832260#832260

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

Reply to this message by going to Community
[https://community.jboss.org/message/832260#832260]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
micste
2013-08-12 13:57:12 UTC
Permalink
micste [https://community.jboss.org/people/micste] created the discussion

"Re: getting process variables available in service task"

To view the discussion, visit: https://community.jboss.org/message/832331#832331

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

Reply to this message by going to Community
[https://community.jboss.org/message/832331#832331]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-08-13 05:27:22 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: getting process variables available in service task"

To view the discussion, visit: https://community.jboss.org/message/832427#832427

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

Reply to this message by going to Community
[https://community.jboss.org/message/832427#832427]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Thomas Colditz
2013-08-13 07:30:17 UTC
Permalink
Thomas Colditz [https://community.jboss.org/people/fellowtom] created the discussion

"Re: getting process variables available in service task"

To view the discussion, visit: https://community.jboss.org/message/832438#832438

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

Reply to this message by going to Community
[https://community.jboss.org/message/832438#832438]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Maciej Swiderski
2013-08-13 08:26:41 UTC
Permalink
Maciej Swiderski [https://community.jboss.org/people/swiderski.maciej] created the discussion

"Re: getting process variables available in service task"

To view the discussion, visit: https://community.jboss.org/message/832449#832449

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

Reply to this message by going to Community
[https://community.jboss.org/message/832449#832449]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Thomas Colditz
2013-08-13 11:11:08 UTC
Permalink
Thomas Colditz [https://community.jboss.org/people/fellowtom] created the discussion

"Re: getting process variables available in service task"

To view the discussion, visit: https://community.jboss.org/message/832472#832472

--------------------------------------------------------------
Thank you very much. So it is.

Kind regards,

Tom
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/832472#832472]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Loading...