Create a custom function to be called in FEEL/DMN

Hi,

I would like to create a custom function that I can call in a DMN FEEL script.

I tried to follow the steps described in that documentation

But, when I try to call the “decr” function in my DMN rule, I still have the error message :

org.camunda.bpm.dmn.feel.impl.FeelException: failed to evaluate expression 'decr(var1)':
no function found with name 'decr' and 1 parameter

Would it be possible to have some help on that topic please ?

Is is my current setup :

  • Camunda engine running in a SpringBoot server

  • pom.xml contains Feel dependency :

      	<groupId>org.camunda.feel</groupId>
      	<artifactId>feel-engine</artifactId>
      	<version>1.15.1</version>
    
    
      	<groupId>org.camunda.bpm.extension.feel.scala</groupId>
      	<artifactId>feel-engine-plugin</artifactId>
      	<version>1.10.1</version>
    
  • Add this bean in the SpringBoot config :
    @Bean
    public ProcessEnginePlugin feelScalaPlugin() {
    return new CamundaFeelEnginePlugin();
    }

  • Define the class as described in the doc :

public class CustomJavaFunctionProvider extends JavaFunctionProvider
{
private static final Map<String, JavaFunction> functions = new HashMap<>();

static {

    final JavaFunction function = new JavaFunction(Arrays.asList("x"), args -> {
        final ValNumber arg = (ValNumber) args.get(0);

        int x = arg.value().intValue();

        return new ValNumber(BigDecimal.valueOf(x - 1));
    });

    functions.put("decr", function);
}

@Override
public Optional<JavaFunction> resolveFunction(String functionName)
{
    System.out.println("=====> resolveFunction with name=" + functionName);
    return Optional.ofNullable(functions.get(functionName));
}

@Override
public Collection<String> getFunctionNames() {
    System.out.println("=====> getFunctionNames ...");
    return functions.keySet();
}

}

Thanks for your help !