How to log variables in grovvy ScriptTask

I’m new to Camunda and BPM in general. I want to place logs in various places in my BPMN so I can learn both the flow and see what data it has. I’m starting my process by sending a /message via REST which seems to work well. I will be sending various processVariables there.

How can I log variables using grovvy? Here is what I have but it causes an error.

println ${execution.getVariable('messageType')}

causes this error:
{
“type”: “ScriptEvaluationException”,
“message”: “Unable to evaluate script while executing activity ‘ScriptTask_00pwmsi’ in the process definition with id ‘Process_0kjz656:8:2707ef49-55be-11ea-b725-9a2cbcbeb0b3’: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.$() is applicable for argument types: (Script9$_run_closure1) values: [Script9$_run_closure1@6d37d63c]\nPossible solutions: is(java.lang.Object), any(), get(java.lang.String), use([Ljava.lang.Object;), any(groovy.lang.Closure), wait()”
}

What am I doing wrong?

-Dave

You don’t need to use the ${}. Just wrote execution.serVariable…

Thanks for the quick reply! Just for my education when do I need to use ${}? I have seen that used in some examples online.

Those are expressions. They are use anywhere you are not doing scripting. “Generally” if you are not writing a script you can do a expression. A expression is usually used for single value lookups. Example: a expression for a gateway sequence flow, or if you wanted a task name to be a specific variable value. I believe there are a few exceptions, but you will find generally you have the same use cases.

Scripting is a different beast, where you are writing multi line script, that may or may not return a result.

“If it’s a text field you can do a expression”. If it’s a multi line text area it is likely for something like a script. Exceptions apply. But gets you started. :slight_smile:

Thanks! :smiley: