FEEL plugin external functions

Dear Camunda community,

We are experimenting with FEEL plugin to do some extended data validation coming from the users. One of the tasks I have is to provide customised messages containing string templates and parameters in the sames as printf works. As I haven’t found a FEEL analogue for printf - I am trying to use external functions declaration in FEEL to use Java methods for this task (String.format or java.text.MessageFormat). I am able to successfully declare and use simple external functions like cos, sin, etc. in a FEEL context.

However, something like

text_format: function(template,text) external {
java: {
class: “java.lang.String”, method_signature: “format(string, string)”
}
}

throws a “hidden” exception inside context variable

[{"text_message":{"cause":null,"stackTrace":[{"methodName":"unpackVal","fileName":"DefaultValueMapper.scala","lineNumber":84,"className":"org.camunda.feel.interpreter.DefaultValueMapper","nativeMethod":false},{"methodName":"unpackVal","fileName":"CustomValueMapper.scala","lineNumber":13,"className":"org.camunda.feel.spi.CustomValueMapper","nativeMethod":false},{"methodName":"unpackVal","fileName":"CamundaValueMapper.scala","lineNumber":41,"className":"org.camunda.feel.integration.CamundaValueMapper","nativeMethod":false}...

What would be a right way to declare something like String.format() or java.text.MessageFormat.format() in a FEEL context?

P.S. Is there a specific reason why method_signature has an underscore?

Best regards,
Ilya

Hi @Ilya_Malyarenko,

currently, it’s not possible to invoke String.format(). The method signature is java.lang.String.format(java.lang.String,java.lang.Object[]) and the parser doesn’t accept arrays like Object[].

I would recommend to implement the custom function provider SPI.

It has an underscore instead of a whitespace because the parser doesn’t support names (i.e. identifiers) with whitespaces.

EDIT: I created an issue to fix the function declaration.

Best regards,
Philipp

Hi @Philipp_Ossler,

Appreciate your kind reply. I will try using FEEL replace function as it might be an option.

Best regards,
Ilya