Service bean call inside a script task

Hello,

with CUBA 7.2 and BPROC I was able to call a service inside the script task, like this example

import com.company.app1.service.CreateProcessDetailsService;
createprocessdetailsservice = com.haulmont.cuba.core.global.AppBeans.get(com.company.app1.service.CreateProcessDetailsService);
createprocessdetailsservice.createAllProcessDetailsExecution(execution.getProcessInstanceId());

How to do it with Jmix 2.x and BPM?

Kind regards,
Mladen

Hello!

Right now, we using flowable engine for BPM, so this is more easy to do

  1. Define Spring Bean in spring boot app:

    @Component("BaseBean")
    public class baseBean {
        public String doSomething() {
            System.out.println("do something");
            return "Do something";
        }
    }
    
  2. Use this bean inside script task. Bean name has to be matched with its name in spring context:

    res = BaseBean.doSomething();
    execution.setVariable("doSomething", res);
    

    image

  3. Run process

    image

  4. Proof of work:

    • Debug call after run the process:

      image
    • stdout in console:

      image
    • Variable has been committed inside completed process:

      image

Conclusion

I recommend using a Spring Bean type of service task if you only need to call a method from a service, rather than relying on a script task worker. However, if you are developing the process during runtime, using a script task worker is acceptable.

Regards,
Dmitry

1 Like

Dear Dmitry,

thank you for this really good answer.
Yes, a process is being developed during the runtime, my customer likes the flexibility, and they understand security implications :slight_smile:

Kind regards,
Mladen

1 Like