Wednesday, September 28, 2016

Being Actionable with C4C Business Object Actions

When you perform custom development on C4C you will usually:
  • Extend standard Business Objects or
  • Create completely new Business Objects with their own properties
In these situations you create additional logic by implementing event handlers for events, such as BeforeSave or AfterModify. These event handlers execute your additional logic during the life cycle of an object.

However: C4C has another way of adding logic: Business Object Actions (or Actions). In this blog I will explain what Business Object Actions are. I will also share two powerful ways I've recently used Actions.

What are Business Object Actions?

I haven't found a clear defintion for Business Object Actions in the reference documentation. Luckily, for a developer it's very intuitive: Think of a Business Object as a class or object, and of an Action as a method of that class or object. If you have a custom Business Object of type 'Car', it might have actions like 'Drive' or 'Refuel' that replenishes the amount of fuel in your car instance.

These actions actually have a lot in common with the Post Processing Framework actions as you might know them from SAP CRM On premise.

What can you do with Business Object Actions?

There are a number of things you can do with Actions:

Call them from Event handlers
Allows you to keep the Event Handler small and simple and hide a lot of complex logic.

Execute on button press
When you generate screens for a custom Business Object that contains Actions, the wizard will automatically generate buttons for each action. For a Business Object Extension, you can add these buttons yourself on the standard screens.

Execute from SOAP or oData service
When you generate a SOAP Webservice in the PDI or an oData Service in the oData explorer you can add your custom actions as methods on the SOAP and oData records, allowing external systems to invoke you business logic.

NOTE: As far as I can tell this will only work for custom Business Objects, not for Business Object Extensions.

Execute in Mass Data Run (Custom BO's only)
A Mass Data Run allows an end user to select a number of records and mass-perform an action on all the selected instances. As the processing occurs in the background, the selection may be very large.

NOTE: Again this only seems to work on custom Business Objects. (I would really love to create an action on a Payment object that would route 0.01 cents to my bank account, but unfortunately this is currently not possible...)

Execute in Workflow
A powerful use of business object actions is in the area of Workflow Rules. A workflow rule typically consists of a timing and condition element and a processing action. One of the types of actions that can used in a Workflow rule is a Business Object Action. This opens up a whole new world of possibilities.

I am sure there are other ways that actions can be used. If I missed some, please let me know in the comments!

How do you create a Business Object Actions?

I assume that you are familiar with general C4C development. If not, check out a series of detailed video recordings by SAP

Creating an action is simple:

First, define an  action inside your custom BO or BO Extension:

After activating the Business Object, create a Script file for this action:

Now you get an empty ABSL script file to work with:

Real life cases

Recently I have been tinkering with Actions and they gave me some interesting solutions to some challenges.

Example 1: Perform a Mass deletion on an custom object

We made a custom BO that stores a large set of temporary lookup data. Unit testing the solution around that dataset was difficult because of old/stale data. I wanted to throw away all data in the underlying table. It is possible to perform multi-deletions in an Object Work List, however this is limited and only works for a few hundred to maybe a thousand records.

The workaround shown here is to schedule a mass-self destruct action for all records of the entity.

I already found out that it is possible to delete an instance with a custom action, like this:

This code above simply deletes the current instance.

When your custom Business Object has both an action and a Query, the option to create a Mass Data run becomes available:

You need to define at least one criteria for your data selection:

After the Mass Data Run has been created, you need to create screens for the Run (do not forget to assign them to a Work Center):

The outcome of this process is that a number of screens are generated:

These screens allow the user to select a number of records through definable selection criteria. In the background a job will be scheduled that executes the defined action for all selected records.

In our case I was able to delete a few hundred thousand records in less than a minute.

Example 2: Create task from service request ticket

Another challenge was to create a Task some time after a Service Request was set to certain status. Without the timing constraint this would have been possible in the BeforeSave event of the Service Request. With worfklow, this becomes quite easy:

First, extend the ServiceReqeust Business Object and define an action to create a task:

Secondly, create a very simple Worfklow rule that contains timing and condition rules:
 Note that the ServiceRequest Business Object is called Ticket here

Create a simple condition: Only execute when the status becomes "Internal Research".

Assign the action to the workflow rule and you are done. Now when you set a ticket to to "Internal Research" and wait for 8 hours, you will see that a task has been created:




8 hours later:

As you can see, Business Object Actions are powerful instruments in the C4C developer toolbox!