Internal Context Functions in Freemarker Script

Dear Forum,

In my current project, I am using input parameter (Type: Script; ScriptFormat: freemarker)
The following example works perfectly. The process instance variable “starterOfInstance” is replaced by the actual value.

When I want to use a Internal Context Functions, in this freemarker template I am getting an error.

For example:

The above example throws an exception:

FTL stack trace ("~" means nesting-related):
- Failed at: ${now()}  [in template "unknown" at line 1, column 38]
----
at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134)
at       
freemarker.core.UnexpectedTypeException.newDescriptionBuilder(UnexpectedTypeException.java:85)
at freemarker.core.UnexpectedTypeException.<init>(UnexpectedTypeException.java:63)
at freemarker.core.NonMethodException.<init>(NonMethodException.java:74)
at freemarker.core.MethodCall._eval(MethodCall.java:67)
at freemarker.core.Expression.eval(Expression.java:101)
at freemarker.core.DollarVariable.calculateInterpolatedStringOrMarkup(DollarVariable.java:100)
at freemarker.core.DollarVariable.accept(DollarVariable.java:63)
at freemarker.core.Environment.visit(Environment.java:331)
at freemarker.core.Environment.visit(Environment.java:337)
at freemarker.core.Environment.process(Environment.java:310)
at freemarker.template.Template.process(Template.java:383)
at   
org.camunda.templateengines.FreeMarkerCompiledScript.eval(FreeMarkerCompiledScript.java:60)
... 50 common frames omitted

Is there a way to configure or to pass Internal Context Functions to freemarker, so they are available for freemarker.

I apreciate any kind of help or hint.

Best Regards

I am trying to add the methods using Freemarker’s TemplateMethodModel
https://freemarker.apache.org/docs/pgui_datamodel_method.html

However, I have no idea how to register the TemplateMethodModel . Can you help me with this?

@philipp.hehnle

Try like this: ${.now}

now : Returns the current date-time. Usage examples: " Page generated: ${.now} ", " Today is ${.now?date} ", " The current time is ${.now?time} ".

In Freemarker special fields are always accessible like .fieldName

https://freemarker.apache.org/docs/ref_specvar.html

Thanks for the hint. However, this does not solve my issue. now() is just a representation of the Internal Context Functions. There are more camunda functions than now(). Moreover, we are developing own functions using FunctionMapper.

I have solved the issue now by using a simple Text Input Parameter instead of freemarker as I do not need any freemarker specific functions but camunda specific function, namely Internal Context Functions.

Nevertheless, thank you for your advise.