cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Unable to delete enum value from dynamic type

bhavirisetty
Active Participant
0 Kudos
1,922

Hello Experts,

I've tried to delete enum value for one of dynamic type from HMC/Impex/Code, I am getting following error,

If I create some value through hmc, I am able to delete them, but not the ones defined in items.xml file, When I try to debug I understand in DB editable column having null for EnumerationValues table, I am not sure why dynamic enums are holding null. If I change editable to true from DB directly, I am able to delete item.

Is there any proper way to delete it? Through code or HMC or Impex?

Note : I am using Hybris 5.7 version.

Thanks

Accepted Solutions (0)

Answers (5)

Answers (5)

0 Kudos

I used this strategy to remove a custom ProductReferenceTypeEnum value from Hybris.

0 Kudos

I believe this would be the full implementation...

import de.hybris.platform.core.model.enumeration.EnumerationValueModel
import de.hybris.platform.enumeration.impl.DefaultEnumerationService
import de.hybris.platform.jalo.Item
import de.hybris.platform.jalo.JaloSession
import de.hybris.platform.jalo.enumeration.EnumerationValue
import de.hybris.platform.persistence.enumeration.EnumerationValueEJBImpl
import de.hybris.platform.servicelayer.model.ModelService
import de.hybris.platform.servicelayer.type.TypeService


final ModelService modelService = spring.getBean('modelService')
final TypeService typeService = spring.getBean('typeService')
final DefaultEnumerationService enumerationService = spring.getBean('enumerationService')


final EnumerationValueModel enumerationValueModel = typeService.getEnumerationValue(enumerationService.getEnumerationValue("LeadStatus", "NEGOTIATION_REVIEW"));
final Item item = (EnumerationValue) modelService.getSource(enumerationValueModel);
((EnumerationValueEJBImpl) item.getImplementation()).remove(JaloSession.getCurrentSession().getSessionContext());
Former Member
0 Kudos

: Can you please provide full implementation class for my reference. I need to do same thing. Thanks in advance.

bhavirisetty
Active Participant
0 Kudos

Hi ,

Thanks for quick response, I am able to figure out alternative solution,

 final EnumerationValueModel enumerationValueModel = typeService.getEnumerationValue(enumerationService.getEnumerationValue("LeadStatus", "NEGOTIATION_REVIEW"));
 final Item item = (EnumerationValue) getModelService().getSource(enumerationValueModel);
 ((EnumerationValueEJBImpl) item.getImplementation()).remove(JaloSession.getCurrentSession().getSessionContext());

Using jalo layer code is not an recommended approach, However it's an one time data correction activity post deployment.

Thanks, Phani

0 Kudos

Hey ,

Unfortunately since 5.1.X version it seems that the editable flag for OOTB enumerations is null by default (instead of 1), so it's not possible to remove the values of OOTB enumerations.

The workaround is to create a new enum without the unwanted values and replace references to the original enum with the newly created enum.

Hope that helps,