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: 

SAP Hybris Loyalty enables organizations to create loyalty programs that deliver a premium customer experience to drive true brand loyalty. It is a loyalty solution that is tightly aligned with your business. It helps you enhance customer retention in a more meaningful way, while encouraging long-term advocacy and referral. You can read more about SAP Hybris Loyalty here:


Actions in Loyalty Rules

SAP Hybris Loyalty provides flexible configuration of your loyalty program by letting you configure rules to manage how the loyalty member is rewarded for his/her activities. As part of the Loyalty Rules configuration, you can set up actions to be performed by the system for certain conditions.

There are a set of standard actions for every rule type. For example, for the rule type ORDER, you can configure the following actions, as shown in the screenshot:

You can use any of the options provided in the list to set the resulting actions if the rule conditions are met.

Now what if you want to send a text message as a resulting action for a rule. As you can see in the screenshot, the standard list of actions does not support an action which can send text messages. How do you do it?

The answer is: Using custom actions.

Using a Custom Action

Loyalty Rules service lets you define a custom action, which can be used in any rule. All you have to do is implement your custom logic as an application and register it as a custom action in the Loyalty Rule service and then use your custom action in the appropriate rule by selecting the "Trigger Custom Action"  from the list of options. You may have a single implementation for multiple custom actions.

When you register a custom action, you will get a unique "Action ID" for it. You can use this id to to differentiate the logic in your custom implementation. More about that later!

update: After 1705 release of SAP Hybris Loyalty, user can enter the custom action id from the UI (eg. SEND_SMS, SEND_CROSS_PRODUCTS etc) instead of system generating a guid for you. This will make it more developer friendly. 1705 release will be available from June 2017.

After registering your custom action, you can go back to your rule and configure it in the results as shown in the screenshots below:


Under the hood

Custom Actions work on the concept of YaaS Events. You can read more about events here.

When this rule gets triggered and if the conditions are met, the rule service would publish an event with a topic named: customActionInvoked. 

You custom implementation must listen to this event and react to it whenever the event occurs.


Implementing your custom action

You can write an application in any programming language or technology of your choice. You application must be able to make REST calls to the Events service to read the events.

For example you have two Custom Actions: Send SMS and Send Email. You just need to have one custom implementation deployment. The most essential part in your implementation is to read the customActionInvoked event topic. You can do this by making a REST call to events service which is part of the essentials package. Hence you do not have to subscribe to Events package to read the events.

The events service requires the topic name and the topic publisher client. The topic name is customActionInvoked. Since the topic was published by the loyalty rule service the topic owner client is hybris.loy-rule. To read the event, make the following REST call to events service. make sure you pass the oAuth token for your project in the request header.

curl -H "Authorization:Bearer 022-35a8b541-b26b-4ee7-9dff-4a9176855ffa" -X POST -d '{"numEvents": 1,"ttlMs": 30000,"autoCommit": false}'

In the request body, you can specify whether you want to auto commit the event, set a lock period for your event and the number of events you want to read in one go. You may want o poll the events service to check for new events periodically. Otherwise you could also opt for push delivery of the events instead of you polling the events service.

For more details on the events service please refer the API docs here:

After you read the event details, you can perform your custom action by executing your logic. A sample event data is shown below. The event data mainly contains the event type and a payload. The payload contains the details pertaining to the member and the activity which was just performed by him. The payload also contains the Custom Action ID. Using this information you should be able to perform an appropriate action in your custom implementation.

Make sure you commit the event using the token after processing, otherwise the events service will always return you the same uncommitted event.

Using custom actions in loyalty rules service, you can now execute any action as per your business use case.