Can i create a custom custom expression function?

i need use to custom func in bpmn conditions. for example, i have a process variable json type. variable has multiple same key and i need getChildKey(jsonVariable), so i want this function access to from condition expression. ${getChildKey(jsonValue) == 200}.

best regard.

Which version of Camunda 7 are you using, i.e., Camunda Run, Camunda Spring Boot Starter?
You can access your Beans from within the JUEL Expresion. So, registering a Bean that provides the desired function should solve your problem. You can also access other classes, as described here.

Alternatively, if you only want to access JSON, you can use Camunda Spin.

1 Like

we use camunda run 7.18, so i create bean function and add a plugin?

Great. There is no need to create a full-fledged plugin.
Camunda run is based on Spring Boot. You can create your beans, package them in a jar, and add the jar to the configuration/userlib directory. After a restart, they should be available in your application.

My bean function that does not take parameters works, but my bean function that takes string and int values ​​as parameters does not work. While the engine is restarting, if there is a parameter in the bean function in the bpmn file, the bean cannot be defined and an error is received. In addition why “CustomExpression” does not work but “customExpression” works? first char have to does not upper case?

my basic bean function bellow

1 Like

i try this function i my bean, and modeler expression

get this error and Engine does not work,

2022-12-12 15:28:58,485 3811 default [main] WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext Caller+0 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:591)
Caller+1 at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
Caller+2 at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)
Caller+3 at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
Caller+4 at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
Caller+5 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
Caller+6 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)
Caller+7 at org.camunda.bpm.run.CamundaBpmRun.main(CamundaBpmRun.java:25)

  • Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘Deneme’ defined in class path resource [org/camunda/bpm/run/CustomExpression.class]: Unsatisfied dependency expressed through method ‘Deneme’ parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
    2022-12-12 15:28:58,688 4014 default [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter Caller+0 at org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter.report(LoggingFailureAnalysisReporter.java:40)
    Caller+1 at org.springframework.boot.diagnostics.FailureAnalyzers.report(FailureAnalyzers.java:143)
    Caller+2 at org.springframework.boot.diagnostics.FailureAnalyzers.reportException(FailureAnalyzers.java:118)
    Caller+3 at org.springframework.boot.SpringApplication.reportFailure(SpringApplication.java:814)
    Caller+4 at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:788)
    Caller+5 at org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
    Caller+6 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
    Caller+7 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295)

APPLICATION FAILED TO START


Description:

Parameter 0 of method Deneme in org.camunda.bpm.run.CustomExpression required a bean of type ‘org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution’ that could not be found.

Action:

Consider defining a bean of type ‘org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution’ in your configuration.

  1. Spring uses the class name and changes the first two letters to lower case. However, you can assign your own name like this:
import org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution;
import org.springframework.stereotype.Component;

@Component("myExpression")
public class CustomExpression {

  public String deneme(final ActivityExecution execution) {
    return execution.getBusinessKey();
  }
}
  1. I cannot replicate your issue. A couple of conditions must be met:
    1. Make sure that you use the Spring Boot Version supported by your Camunda Run version. For 7.18. use Spring Boot 2.7.x. I recommend changing the scope of the dependencies to provided, to avoid version conflicts at run-time:
<dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot</artifactId>
      <version>2.7.0</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.camunda.bpm.springboot</groupId>
      <artifactId>camunda-bpm-spring-boot-starter</artifactId>
      <version>7.18.0</version>
      <scope>provided</scope>
    </dependency>
</dependencies>
  1. Add a spring.factories file to the resources\META-INF directory of the project including the beans, i.e.,
 org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
 io.camunda.forum.CustomExpression
1 Like

thank you Stephan, this solved my problems.

1 Like