Creating a Custom Business Object

After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Create a customer-specific solution
  • Create a custom business object



In this unit we will leverage a sample development project that accompanies us throughout the development lifecycle and in demonstrations of the following lessons and units. The solution serves as a container for the development project and the first development item, which is a custom business object. The object is a lightweight version of a sales contract. Hence we name it "SimpleContract" and the solution "SimpleContractSolution". However, we will add other development items to the solution later as well.

If you have access to an SAP Sales/Service Cloud tenant and to the SAP Cloud Applications Studio, you can follow the demonstrations.

Create a Solution

In this unit, we will create a new solution and a new custom business object from scratch. We will create the user interface (UI) for this business object and implement business logic for it.

Before we can go ahead and create development content, like new business objects, we need to create a solution first. This is the container where we store all related development content. The following video shows how to log on to the system and create the new solution. 

Keep in mind that you have to set up the system details in the Studio settings. If the login dialog does not contain your system, you can jump to the right place in the settings by clicking the pencil icon. For more details, refer to Unit 2.

In the Create Solution dialog, pay attention to the Deployment Unit field. Make sure you choose Customer Relationship Management here. Other deployment units are used only in very rare cases or when developing solution templates. Click here for more information on deployment units.

In this training we create a customer specific solution and assume we are working on the customer's tenant. If you want to work on your own "partner" tenant and move the solution later to a customer's tenant, make sure you carry out the customer assignment switch accordingly.

The Simple Contract Business Object

The Simple Contract business object serves as an example that contains the most important structure elements. It helps demonstrate the different capabilities of SAP Cloud Applications Studio and the extension framework. It consists of:

  • Fields with different data types and pre-defined labels on the root node.
  • A sub node "Items" that contains more fields and has a 0:n relationship to the root node. Hence, we can have multiple "Item" instances per contract.
  • Dependent Objects that allow us to reuse existing objects as part of our BO.
  • Associations that represent references to other business objects which can be used for navigation and property access.
  • Actions to encapsulate business logic.
  • A message that can be shown to the user (this will be shown in the next unit).

Let’s have a look at the various fields in more detail. Let’s begin with the root node’s fields, sometimes referred to as header fields.

  • The first two fields allow us to store an ID and a description for the contract. The attribute AlternativeKey for the ContractID field ensures that the ID is unique amongst all SimpleContract instances. The system creates a technical identifier called UUID transparently in the background and uses it internally for referencing the object. The alternative key field ContractID is human readable and hence, more user friendly. Similar to the IDs of accounts and employees, it is usually used in the front end to enable end users in creating references to other business objects.
  • The fields AccountID and ContractOwnerID can store IDs of an account and an employee. To access data of the respective objects, these IDs must be resolved to object references, that are then stored in the respective associations.
  • The date fields allow users to specify different dates for the contract processing.
  • The ContractAmount field is used to store the sum of the item’s amounts. It will be calculated by a script, implemented for the CalculateReportAmount action and executed whenever the object is saved.

We will create the definition of the business object and implement the logic in the following sections and lessons. To make all of this accessible for end users, we generate screens for the object and adapt them to our needs.

Create a Custom Business Object

In the next step we create a new custom business object. It's a common approach to place it in a separate folder, to keep track of the development content and keep the solution clean. We show that in the following video. The source code for the business object definition will be copy and pasted during the video. You can find the script snippet below.

The folder structure helps to keep the solution tidy. In the upcoming demos of this unit, you will see how content is added as we go along and why it makes sense to have a separate folder for each business object. 

If you have access to an SAP Sales/Service Cloud tenant and want to follow along with the demonstrations, you can use the following code snippet for the business object definition.

Code snippet
import AP.Common.GDT;
import AP.CRM.Global;
import AP.FO.BusinessPartner.Global; 
import AP.PC.IdentityManagement.Global;
import AP.FO.ProductDataMaintenance.Global;

businessobject SimpleContract raises CalculationResultMsg
    message CalculationResultMsg text "The item total is: &1" : Amount;

    [Label("Contract ID")] element ContractID : ID;
    [Label("Contract Description")] element ContractDescription : LANGUAGEINDEPENDENT_MEDIUM_Description;
    [Label("Account")] element AccountID : BusinessPartnerInternalID;
    [Label("Contract Owner ID")] element ContractOwnerID : EmployeeID;
    [Label("Agreement Date")] element AgreementDate : Date;
    [Label("Effective Date")] element EffectiveDate : Date;
    [Label("Expiration Date")] element ExpirationDate : Date;
    [Label("Contract Amount")] element ContractAmount : Amount;

    node Items [0,n]
        [Label("Item ID")] element ItemID : ID;
        [Label("Product ID")] element ProductID : ProductInternalID;
        [Label("Quantity")] element Quantity : Quantity;
        [Label("Price")] element Price : Amount;

        association ToProduct to Material;

    [DependentObject(AttachmentFolder)] node Attachment; 
    [DependentObject(TextCollection)] node TextCollection;

    association ToAccount to Customer;
    association ToContractOwner to Employee;

    action CalculateReportAmount;

Don't forget to Save and Activate the code!

Log in to track your progress & complete quizzes