on ‎2019 Jan 22 2:00 PM
Hi ,
I am creating an impex by using DynamicConstraints as below by refering OOB feature.
INSERT_UPDATE DynamicConstraint; active[allownull = true, default = true]; id[unique = true]; severity(code, itemtype(code)); message[lang = en]; target[allownull = true]; type(code); language(code); expression; constraintGroups(id);
; ; ProductIsEXConstraint ; ERROR:Severity ; The attribute value should not be null. ; de.hybris.platform.core.model.product.ProductModel ; Product ; BEANSHELL ; return getProductTypeCategoryCode().getCode().equalsIgnoreCase("mattresses")? true:false ; pcmCoreAttributesCoverageGroup ;
Here Condition in the above scripts is specific to some particular products only but the error message is showing in core attributes irrespective of products.How to add condition to particular product category or how to write java logic with more than one statement in beanshell. Kindly let us know if anyone faced the same issue.
Request clarification before answering.
It worked with ? false:true. the validation message works when it returns false.I was testing reverse way.
Thanks Arvind
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Arvind,
Yes , I have followed the same syntax of ApprovalStatus attribute. getProductTypeCategoryCode() method will be available in productModel to find the category of the product. The issue here is validation is working for both mattresses and other products as well. I need to apply the validation to only same particular products. Kindly let me know if any issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You don't need ? true:false in the expression i.e. it should be just
return getProductTypeCategoryCode().getCode().equalsIgnoreCase("mattresses")
The Creating Dynamic Constraints section states:
General regulation to write DynamicConstraint script, is that the expression must return object, which somehow can be evaluated as a boolean true or false value (logic or textual).
Another thing that I am not able to understand in your code is getProductTypeCategoryCode(). There is nothing like productTypeCategoryCode in OOTB ProductModel. Is this your custom attribute? If it is a custom attribute of some enumtype, are you sure the enumtype has <value code="mattresses"/>?
Please look at the code given below:
INSERT_UPDATE DynamicConstraint; active[allownull = true, default = true]; id[unique = true]; severity(code, itemtype(code)); message[lang = en]; target[allownull = true]; type(code); language(code); expression; constraintGroups(id);
; ; ProductApprovedDynamicConstraint ; ERROR:Severity ; The attribute value for "Approval" should be "approved". ; de.hybris.platform.core.model.product.ProductModel ; Product ; BEANSHELL ; return getApprovalStatus().getCode().equalsIgnoreCase("approved") ; pcmCoreAttributesCoverageGroup ;
You can call getApprovalStatus() on a Product instance (you can test it by executing the following groovy code) because the OOTB ProductModel has an attribute, approvalStatus:
product = modelService.create("Product")
product.name='Test Product'
product.code='12345'
println product.getApprovalStatus()
But with the OOTB ProductModel, the following code will throw error:
println product.getProductTypeCategoryCode()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.