In this article we’ll be talking about actions and events. In previous article we saw about What is business object and structure of business object.
We used BODL (Business Object Definition language) for defining the business object. For actions and events, we are going to use ABSL (Advanced Business Scripting Language). This is the other set of language that is in SAP Cloud Applications Studio to be able to define actions and behavior for particular business objects.
Now we can apply ABSL to objects by using two things:
- Actions
- Events
Before entering into the Action and events we will see this table.
[table id=10 /]
Depending on whether you are implementing the business logic for business objects or the business logic for business object extensions, you can create the above script files.
In later article, we will see about business object extension.
What is Actions?
- An action is an element of a business object node describes an operation performed on that node.
- The Action operates on a set of node elements or instances that have been created or changed.
- Action script files are provided if you have added actions to your business object definition.
- Actions can be defined for custom and standard business objects.
- Actions can be triggered from the user interface, events, or other actions
BODL: import AP.Common.GDT; businessobject Bonus { element ID : ID; action close; action cancelled; action CreateProjectCose; //Actions }![]()
What is event?
- An event is used to compute data that can be derived from other node elements.
- The system executes an event implemented for custom business objects in ascending order from bottom to top, that is, from subnode to root node. In case of events implemented for extended business it is the reverse: the system executes an event in descending order from top to bottom, that is, from root node to subnode.
The following events are provided by the system:
AfterLoading (Only available for Business Objects)
- You can implement this event to modify transient fields of the current node of a business object. The system
executes the AfterLoading event when it reads a node instance of a business object from the data base. - You cannot use an AfterLoading event to do the following:
- Read and modify a transient field of another node
- Modify a persistent field
- Create or delete a node
- Call an action
AfterModify (Available for Business Objects & Business Object Extension)
- This happens every time some object is modified, somebody clicks enter, selects something from a search help, after an action is executed it’ll call the AfterModify event.
- This object has not been saved yet so you can perform any kind of logic or changes in AfterModify Script.
BeforeSave (Available for Business Objects & Business Object Extension)
- BeforeSave is triggered, after a user has clicked Save for an object.
- You can perform any kind of logic or changes. There is no restriction.
OnSave (Available for Business Objects & Business Object Extension)
[pullquote] Please note that the system always executes the OnSave validation after having executed the
BeforeSave event.[/pullquote]
- You can use the OnSave validation to check whether a business object can be saved.
- A validation is used to check if particular conditions are fulfilled, such as the conditions for saving a business object node.
- Validations can only read data and cannot change any values.
- The result of a validation must always evaluate to a Boolean value (true or false).
- The system executes validations in no particular order. It executes all of the validations, i.e., even if a validation already returned false, the remaining validations are executed.
Example: A validation that checks whether the string “0123” is contained in the sampleData field: if (this. sampleData.Contains("0123")) { return(true); } else { return(false); }
Action validation (Only available for Business Object Extensions)
- You can use an action validation to check whether an action of an SAP business object can be executed.
- As a prerequisite, the action must be released in the public solution model (PSM).
- The system executes the validation before it calls the corresponding action. The return value determines whether the action is executed or not.
- You can raise messages defined in the business object extension if the action cannot be executed.
In our next article, we are going to discuss about Reusable Library. If you want to learn more about SAP ByDesign, Don’t forget to subscribe here.