Pass DelegateService task into service

564 views
Skip to first unread message

sojk...@gmail.com

unread,
Jun 11, 2014, 10:29:53 AM6/11/14
to camunda-...@googlegroups.com
Hi,

How can I pass service DelegateTask object into service (via expression)?

We tried use expression in modeler with

#{sentMessageService.sendingMessage(task)}

but we got an error
Message: Unknown property used in expression: #{sentMessageService.sendingMessage(task)}. Cause: Cannot resolve identifier 'task'

but this expression we successfully used on user task.. is there different behavior?

Best regards
Jiri Sojka

Daniel Meyer

unread,
Jun 12, 2014, 1:32:54 AM6/12/14
to camunda-...@googlegroups.com, sojk...@gmail.com
Hi Jiri,

the "task" variable is only available inside the scope of a UserTask. You could use your expression for a taskListener. http://docs.camunda.org/latest/guides/user-guide/#process-engine-delegation-code-task-listener

If you have a service task, the process engine cannot know which task you are talking about. You could use the TaskService inside the JavaDelegate implementation and query for the task, though...

public class MyServiceTask implements JavaDelegate {

 
public void execute(DelegateExecution execution) throws Exception {

    execution
.getProcessEngineServices()
     
.getTaskService()
     
.createTaskQuery()
     
.processInstanceId(execution.getProcessInstanceId())
     
.taskDefinitionKey("approveInvoice")
     
.singleResult();
 
}
}

However: this will only work if the task is currently active, on a parallel branch of execution.

Does this help you solve your problem?

Cheers,
Daniel

sojk...@gmail.com

unread,
Jun 12, 2014, 3:41:05 AM6/12/14
to camunda-...@googlegroups.com, sojk...@gmail.com
Hi Daniel,

thanks a lot for your tips... We try to use camunda plugin in grails, but we are beginner with this framework... Our idea is have some easily tested code (in grails) and use it in camunda.

We need just get a process variable (in service task), then we are able to get our grails domain object (but it should be groovy class).

So the main question is if we can use groovy class and use it like standard java class which implements JavaDelegate...

Thanks a lot again.

Beste regards
Jiri Sojka

Daniel Meyer

unread,
Jun 13, 2014, 7:21:29 AM6/13/14
to camunda-...@googlegroups.com, sojk...@gmail.com
Hi Jiri,

Maybe you could use a Script Task? Script tasks can be written in Groovy.

Cheers,
Daniel

Martin Schimak

unread,
Jun 13, 2014, 7:30:54 AM6/13/14
to camunda-...@googlegroups.com
Hi Jiri,

I am not exactly sure what you want to achieve... but I recommend that you use plain Grails Service Classes, put them beneath services folder and call them via their bean name from a camunda Service Task "expression" attribute. The grails services are spring beans and therefore directly available via JUEL expression language. You can directly call any method and e.g. deliver a process variable as param… or as an alternative the camunda 'execution' object reference.

Does this help?

Martin.
--
You received this message because you are subscribed to the Google Groups "camunda BPM users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Meyer

unread,
Jun 13, 2014, 7:41:24 AM6/13/14
to camunda-...@googlegroups.com
That sounds like a good approach, thanks Martin.

Daniel

sojk...@gmail.com

unread,
Jun 13, 2014, 7:44:05 AM6/13/14
to camunda-...@googlegroups.com
Hi Martin,

we have our grails domain objects and each has own process instance. We want to create service/class and use it in service task... But into this task we need pass some object and use it for find our grails object..

I created standard groovy class(implements JavaDelegate). It works for me. From delegate i am able to get business key(it contains our grails domain object id) and find grails domain object...


Is there any better solution?

Thanks a lot.

Jiri.

Martin Schimak

unread,
Jun 13, 2014, 9:32:35 AM6/13/14
to camunda-...@googlegroups.com
Hi Jiri,

If I remember correctly you can access the businessKey in a camunda JUEL expression like "execution.processBusinessKey". (Is that correct Daniel? I am on the go...) From your process definition you could then directly call a grails service method like

<serviceTask id="…" camunda:expression="#{myService.myMethod(execution.processBusinessKey)}" .../>

In my mind, this has the advantage that you now define a general "business" service method just passing the id of your domain object, and get spring based transactional behavior even when you don't call the service method from the process instance but from somewhere else. So you encapsulate your business logic at the place where grails "wants" it to be encapsulated… and don't need to code any intermediate camunda delegate.

Martin.
--
You received this message because you are subscribed to the Google Groups "camunda BPM users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.

Martin Schimak

unread,
Jun 13, 2014, 9:37:08 AM6/13/14
to camunda-...@googlegroups.com
Furthermore, you can then easily mock "myService" in your test class by using camunda's Mocks.register() - just as shown in the test template of http://grails.org/plugin/camunda

Martin.
Reply all
Reply to author
Forward
0 new messages