CRM and CX Blogs by SAP
Stay up-to-date on the latest developments and product news about intelligent customer experience and CRM technologies through blog posts from SAP experts.
Showing results for 
Search instead for 
Did you mean: 
0 Kudos


In this blog, we will create new Structure Type in SmartEdit and assign it to one of the CMS Component.

We will enhance OOTB CMSTimeRestriction with cronExpression and add a Guide link to this component which takes CMS Manager to third party site.

This blog is based on SAP Commerce 1811.

Customization (Core Part)

  • Extend OOTB CMSTimeRestriction with new attribute cronExpression in myextension-items.xml

       <itemtype code="CMSTimeRestriction" extends="AbstractRestriction" autocreate="false" generate="false">
<attribute type="java.lang.String" qualifier="cronExpression">
<persistence type="property" />

  • Update Localization in Expression

  • Extend OOTB CMSTimeRestrictionEvaluator with cron expression support

public class CustomCMSTimeRestrictionEvaluator extends CMSTimeRestrictionEvaluator
private static final Logger LOG = LogManager.getLogger(CustomCMSTimeRestrictionEvaluator.class);

public boolean evaluate(final CMSTimeRestrictionModel timeRestriction, final RestrictionData context)
final boolean isEvaluate = super.evaluate(timeRestriction, context);
return isEvaluate && evaluateCronExpression(timeRestriction);

private boolean evaluateCronExpression(final CMSTimeRestrictionModel timeRestriction)
if (StringUtils.isBlank(timeRestriction.getCronExpression()))
return true;

Date now = (Date) getSessionService().getAttribute("previewTime");
if (now == null)
now = Boolean.TRUE.equals(timeRestriction.getUseStoreTimeZone()) ? getTimeService().getCurrentTime() : new Date();

final CronExpression cronExpression = new CronExpression(timeRestriction.getCronExpression());
return cronExpression.isSatisfiedBy(now);
catch (final ParseException e)
LOG.error("Provided CronExpression {} is not valid.", timeRestriction.getCronExpression(), e);

return false;

  • Override bean definition in myextension-spring.xml

    <bean id="cmsTimeRestrictionEvaluator" class="" autowire="byName">
<property name="sessionService" ref="sessionService" />
<property name="timeService" ref="timeService" />


Our Core functionality is done. Now CMSTimeRestriction support cronExpression as well and CMS Manager can control component visibility based on cron expression as well.

Customization (SmartEdit Part)

The newly created attribute (cronExpression) in CMSTimeRestriction will automatically visible in SmartEdit. Lets begin creating new CMS Structure Type -> cronExpressionGuide which will have link which takes CMS Manager to third party site (e.g.

  • Lets first create one custom SmartEdit extension. Please follow these links to setup & create one custom extension e.g. trainingsmartedit.

  • Once new extension is created, Go to trainingsmartedit/web/features/trainingsmarteditContainer folder and create a new package structure /components/genericEditor/cronExpressionGuide (Here we will define our new structure type html).

  • Create cronExpressionGuideTemplate.html inside cronExpressionGuide folder as per below.

<a href="" target="_blank">Generate Cron Expression</a>

  • Now we need to create Generic Editor Mapping Service to map new structure type cronExpressionGuide to a virtual field (CronExpressionGuide). This virtual field we can assign to CMSTimeRestriction.

  • Create new folder config inside genericEditor (/components/genericEditor/config) and add one new file cmsTrainingGenericEditorMappingService.js under config folder.

  • Create new field mapping like this inside cmsTrainingGenericEditorMappingService.js

angular.module('cmsTrainingGenericEditorConfigurationServiceModule', ['cmsGenericEditorConfigurationServiceModule', 'editorFieldMappingServiceModule'])
.run(function(editorFieldMappingService) {

// CronExpressionGuide is the virtual field
editorFieldMappingService.addFieldMapping("CronExpressionGuide", null, null, {
template: "cronExpressionGuideTemplate.html"

  • Here we have added a mapping of our newly created Structure Type with virtual field CronExpressionGuide.

  • Inject editor field mapping service into trainingsmarteditcontainerModule.ts file.

imports: [

  • Finally add this virtual field to CMSTimeRestriction. Add the below bean definition in trainingsmartedit-spring.xml

	<bean id="cronExpressionGuideTypeAttributePopulator" class="de.hybris.platform.cmsfacades.types.populator.CmsStructureTypeComponentTypeAttributePopulator">
<property name="cmsStructureType" value="CronExpressionGuide" />

<bean class="de.hybris.platform.cmsfacades.types.service.impl.DefaultComponentTypeAttributeStructure" p:typecode="CMSTimeRestriction" p:qualifier="cronExpressionGuide">
<property name="populators">
<ref bean="i18nComponentTypeAttributePopulator" />
<ref bean="cronExpressionGuideTypeAttributePopulator" />

  • Update localization in Expression Guide

  • Optionally, we can define ordering as well like this

	<alias name="customCmsStructureTypeModeAttributeFilterList" alias="cmsStructureTypeModeAttributeFilterList"/>
<bean id="customCmsStructureTypeModeAttributeFilterList" class="org.springframework.beans.factory.config.ListFactoryBean" parent="defaultCmsStructureTypeModeAttributeFilterList">
<property name="targetListClass" value="java.util.LinkedList"/>
<property name="sourceList">
<list merge="true">

<bean parent="cmsStructureTypeModeAttributeFilter">
<property name="constrainedBy">
<bean parent="cmsEqualsTypeAndModeBiPredicate" p:typeCode="CMSTimeRestriction" p:mode="DEFAULT"/>
<property name="order">



Build Step -

Make sure at the time of SmartEdit setup, assuming you have already done ant npminstall.

  • Now run ant clean all and this will compile our newly added service and generate new trainingsmarteditContainer.js file.

  • Once build is successful, start the Hybris Server and open SmartEdit.

  • Make sure that the following impex run at the time of setup.

INSERT_UPDATE SmartEditConfiguration;key[unique=true];value
;applications.trainingsmartedit;{"smartEditLocation":"/trainingsmartedit/trainingsmartedit/js/trainingsmartedit.js","extends": "cmssmartedit"}
;applications.trainingsmarteditContainer;{"smartEditContainerLocation":"/trainingsmartedit/trainingsmartedit/js/trainingsmarteditContainer.js","extends": "cmssmarteditContainer"}

  • Finally test the changes, Create new CMSTimeRestriction, and you will see Cron Expression Guide with "Generate Cron Expression" link.


This way we can create any type of custom Structure Type and map it to the component by introducing virtual field.



Shreshtt Bhatt