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.
cancel
Showing results for 
Search instead for 
Did you mean: 
arun_suresh
Explorer
Overview

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:

https://www-acc.hybris.com/en/products/marketing/building-loyalty-advocacy

 

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 https://api.beta.yaas.io/hybris/events/v1/topics/hybris.loy-rule/customActionInvoked/read -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:

https://devportal.yaas.io/services/beta/events/latest/#

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.
{
"events":[
{
"eventType":"customActionInvoked",
"payload":"{\"tenant\":\"loyqm1605test\",\"customActionId\":\"3a23a8bc752a44daba868aa449a6f84e\",\"eventData\":{\"ruleType\":\"REGISTRATION\",\"member\":{\"memberId\":\"a7a716faee4ec94419f9ae8a897742b7\",\"memberNumber\":\"619854193\",\"programId\":\"a9dd04e1f51e46d99a1afce83284adf1\",\"customerId\":\"C0986307124\",\"customerEmail\":\"lohitstage01@hybristest.com\",\"dateValidFrom\":\"2016-04-14\",\"dateValidTo\":\"2090-05-05\",\"tierId\":\"47f17fb3c2bd4f5fafd3841ae1ffc4a9\",\"tierHistory\":[{\"tierId\":\"47f17fb3c2bd4f5fafd3841ae1ffc4a9\",\"tierUpdateDate\":1.460619854209E12,\"tierActivity\":\"UPGRADE\"}],\"totalEarnedPoints\":0.0,\"totalBalancePoints\":100.0,\"totalQualifyingPoints\":100.0,\"totalExpiredPoints\":0.0,\"createdBy\":\"C0986307124\",\"memberStatus\":\"ACTIVE\",\"preferredLanguage\":\"en\"},\"memberActivity\":{\"memberActivityId\":\"396bb5b60ff84b909d207e6e17d1d966\",\"memberId\":\"a7a716faee4ec94419f9ae8a897742b7\",\"refId\":\"\",\"activityType\":\"REGISTRATION\",\"transactionAmount\":0.0,\"programId\":\"a9dd04e1f51e46d99a1afce83284adf1\",\"tierId\":\"47f17fb3c2bd4f5fafd3841ae1ffc4a9\",\"year\":\"2016\",\"quarter\":\"Q_2\",\"month\":\"APR\",\"week\":16,\"createdBy\":\"C0986307124\",\"activityStatus\":\"NEW\"}},\"pointsData\":{\"membershipId\":\"a7a716faee4ec94419f9ae8a897742b7\",\"qualifyingPointsEarned\":100.0,\"redeemablePointsEarned\":100.0,\"redeemablePointsUsed\":0.0,\"redeemablePointsBalance\":100.0,\"qualifyingPointsBalance\":100.0,\"qualifyingPointsExpired\":0.0,\"redeemablePointsExpired\":0.0,\"processingTime\":\"491ms\",\"processedAt\":\"2016-04-14\",\"newTierId\":\"47f17fb3c2bd4f5fafd3841ae1ffc4a9\",\"rulesApplied\":[\"ecdcbb024a51458893ff9d519b03d261\",\"bee01f10e8174c9cbb44e8c65bee5df9\"]}}",
"tenant":"loyqm1605test",
"id":"8ec639c8-123d-4db8-ac7c-db327730592c",
"sourceClient":"hybris.loy-rule",
"createdAt":1460619855336
}
],
"token":"eyJ0Z3AiOnsidG9waWMiOiJoeWJyaXMubG95LXJ1bGUuY3VzdG9tQWN0aW9uSW52b2tlZCIsImdyb3VwIjoibG95cW0xNjA1dGVzdC5sb3kxNjA1eW1rdCIsInBhcnRpdGlvbiI6MH0sIm9mZnNldCI6MTgzLCJuZXdPZmZzZXQiOjE4NCwidXVpZCI6Ijg1NGU0MzU5LTJhMTMtNGZlYi05MTM2LTJkMWJjMTJjMDYzNiJ9"
}

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.