Associate flowable task with method

Hello Readers,

Until now I’ve known that service task can be associated with a class like below,

And, the class should implement JavaDelegate interface and there should be a method called execute with DelegateExecution as it’s parameter.

Is it possible that I can associate a service task with a simple method like below??

Service Task:

Class:
public class HelloWorld {
private static final Logger LOGGER = Logger.getLogger(HelloWorld.class.getName());
public void helloWorld(){
LOGGER.info(“Hello, this is working atleast”);
}
}

Regards,
Ashmita Sinha

You can try setting the expression on your service task:

https://flowable.org/docs/userguide/index.html#bpmnJavaServiceTaskXML

Hello William,

I’ve tried this,

but this gives error: Unknown property used in expression: #{helloWorld.helloWorld()}.

Which means, it is unable to get the bean and call helloWorld(). Is tere anything else which can be done?

Thanks in advance !

Regards,
Ashmita Sinha

@aashi,

Here’s a sample app https://github.com/unamanic/forum-flowable-expression. I tend to use $ as opposed to #, however either should work. In order to use expression in this way helloWorld needs to be registered as a bean.

  • The BPMN in the sample I have a service task with flowable:expression="${demoService.hello()}".
  • The DemoService is as follows:
package com.example.flowableexpression.services;

import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

@Service
@Log4j2
public class DemoService {

    public String hello(){
        log.info("executing DemoService.hello()");
        return "hello";
    }
}

@wwitt

I tried the github project which you mentioned and that worked fine.

Could you please check https://github.com/PMD123/Flowable.

Error which I’m getting: org.flowable.common.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier ‘helloWorld’

@akki

I think the biggest complication in your source is that you are manually creating the process engine. I don’t think that the process engine is Spring aware when you create it this way, so it won’t know to inject named beens into the expression handling. This is the same reason that your JavaDelegate has to use class instead of delegateExpression. There are methods to add additional functions to expression handling like in ProcessEngineConfigurationImpl where we initialize the function delegates. But the simplest solution would be to import flowable-spring or flowable-spring-boot-starter and let the engine find your beans.

Here’s an example project if you don’t want to use the starter:

Additionally, it’s possible to register custom functions that can be used in expressions. See the org.flowable.common.engine.api.delegate.FlowableFunctionDelegate interface for more information.