cancel
Showing results for 
Search instead for 
Did you mean: 

Create DynamicConstraint with beanshell and "for" loop

former_member743363
Discoverer
0 Kudos
326

Hi. I am creating an impex by using DynamicConstraints as below.

INSERT_UPDATE DynamicConstraint;id[unique=true];severity(code,itemtype(code));active;annotation;target;type(code);language(code);message[lang=en];expression
                                  ;OnlyOneComponentMayBeDisplayed;ERROR:Severity;true;de.hybris.platform.validation.annotations.Dynamic;my.domain.model.components.CategoryComponentModel;CategoryComponent;BEANSHELL;my message;"cnt = 0; components = getCategory().getComponents(); for(c : components){if (c.isDisplayed()) {cnt++;}} return cnt <= 1;"

And I want to make sure the displayed component is the only one for the category before I save it. This works in java code, but in the DynamicConstraint throws an error message for any Component state (isDisplayed true or false).

Is it possible to do what i want with DynamicConstraint?

Accepted Solutions (0)

Answers (0)