0

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>
Ronan Keane
  • 189
  • 8

1 Answers1

1

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.

David E. Jones
  • 1,721
  • 1
  • 9
  • 8
  • That's great, thank you. Wrt context fields being always available, I wanted to use userGroupId which afaik is not always available like say ec.user.userId is available. To get around this I was going to add a couple of EECAs to create/delete a corresponding UserPreference key and value on create/delete of a UserGroupMember record. Obviously clumsy, but is there a better way to do it? – Ronan Keane Dec 15 '16 at 09:03
  • Sorry, just to clarify/correct - while in my own use case I am at this time restricting userGroup membership to one group per user only, what would be correct for the general case would be a list of group memberships for that user that would be checked against in a condition expression. – Ronan Keane Dec 15 '16 at 10:36
  • Look at the UserFacade interface (for ec.user), there are methods for data about user groups, preferences, etc. – David E. Jones Dec 15 '16 at 16:36