Expand an expression in a condition?

80 Views Asked by At

I am trying to use the 'conditionExpression' field of the StatusFlowTransition entity in a status widget.

But I think you can't expand say ${statusTransition.conditionExpression} within a condition in Moqui?

How is the conditionExpression field supposed to be used then?

e.g.

<widgets>
   <link url="${statusChangeTransition ?: 'updateStatus'}"  text="StatusTransitionNameTemplate" text-map="statusTransition" parameter-map="[statusId:statusTransition.toStatusId]" condition="${statusTransition.conditionExpression}" />
</widgets>
1

There are 1 best solutions below

3
On BEST ANSWER

The key part of your question is: how do I evaluate a Groovy expression that is in a variable? You can do this directly with the Groovy API but the easiest and most efficient (because compiled expressions are cached) way to do this is to use the ResourceFacade.condition() method, ie:

<link ... condition="ec.resource.condition(statusTransition.conditionExpression, '')"/>

The second parameter is the debug location and can be empty. When using the conditionExpression it is important to keep your conditions simple and only use context fields that are always available. You can also pass a third parameter to the condition() method that is a Map with fields to use in the conditionExpression in addition to what it in the current context.