Improving the User Experience

Objectives

After completing this lesson, you will be able to:

  • Arrange fields in the app.
  • Provide input help.

UI Adjustment

In this section, you will learn how to control field properties in the behavior definition and how to adjust the UI in the metadata extension.

Arranging Fields in the UI

Making Fields Read-only

Once you have made the fields read-only, you can see that it makes sense to rearrange them. You do this by annotating the corresponding fields of the projection. Most commonly, you do this in a metadata extension.

Metadata extensions are standalone repository objects that contain the annotations belonging to a particular CDS entity. The idea behind them is to make it easier to understand both the definition of the CDS entity and the annotations by separating them. Otherwise, the CDS definition would become very long and difficult to read.

If you want to use a metadata extension in conjunction with a CDS view, the CDS view must contain the annotation @Metadata.allowExtensions: true. The generator takes care of this for you and automatically generates both a metadata extension for the projection view and the corresponding annotation in the projection view itself.

There are two important UI annotations that you might need to change in the metadata extension. The first is @UI.LineItem. This is an array in which you set the attribute position. This determines the position of the column in the report list page of the app.

The second annotation is @UI.identification. This is, again, an array in which you also set the attribute position. This determines the position of the field in the single object page. that is displayed during the create or update operation.

Rearranging the Fields

How to Control Field Properties

Input Help

In this section, we will learn about providing value help to the users. Watch this video to learn more.

Adjust the User Interface

In this exercise, you adjust the user interface of your app; either directly by editing the UI-metadata, or indirectly by adjusting the business object behavior and the data model projection.

Template:

  • none

Solution:

  • /LRN/S4D400_C_FLIGHT (Behavior Projection)
  • /LRN/S4D400_C_FLIGHT (Metadata Extension)
  • /LRN/S4D400_C_FLIGHT (Projection View)

Prerequisites

You completed the previous exercises. You created and filled the database table Z##AFLGT (where ## is your group number) and generated the development objects for an OData UI Service.

Task 1: Adjust the Behavior

Exclude the standard operations update and delete, and set the field PlaneTypeID to read-only .

Note

These changes should only apply to your OData UI Service. The business object itself should still support the creation and deletion of flights, and the changing of the airplane type.

Steps

  1. In the behavior projection for your service, disable the standard operations create and delete.

    1. Open the behavior projection Z##_C_Flight (where ## is your group number).

    2. Add comment markers in front of the statement use create; and use delete;.

      To add the comment markers, proceed as usual: select the code rows you want to comment and press Ctrl + <.

      Your code should then look like this:

      Code Snippet
      Copy code
      Switch to dark mode
      12345
      // use create; use update; // use delete;

  2. In the behavior projection of your business object, set the field PlaneTypeID to read-only.

    1. In the behavior projection, add the following code:

      Code Snippet
      Copy code
      Switch to dark mode
      123
      field (readonly) PlaneTypeID;

      Note

      The precise position of the statement is not important. We suggest that you place it before the use ... statements.
  3. Activate the behavior projection.

    1. Press Ctrl + F3 to activate the behavior projection.

Task 2: Adjust the UI Metadata

Configure CarrierID and ConnectionID so that they are available as selection fields on the report list page. Change the field sequence on the object page so that PlaneTypeID is displayed before Price and CurrencyCode.

Steps

  1. Edit the Metadata Extension of the projection view (Z##_C_Flight). Annotate view elements CarrierID and ConnectionID with suitable values for annotation @UI.selectionField: [{ position: }].

    1. Open the metadata extension Z##_C_FLIGHT where ## is your group number.

    2. Add the highlighted code:

      Code Snippet
      Copy code
      Switch to dark mode
      12345678910111213141516171819
      @UI.lineItem: [ { position: 10 , importance: #MEDIUM } ] @UI.identification: [ { position: 10 } ] carrierid; @UI.lineItem: [ { position: 20 , importance: #MEDIUM } ] @UI.identification: [ { position: 20 } ] connectionid;
  2. Change the position of the PlaneTypeID field on the object page. Place it between FlightDate and Price.

    Hint

    The position on the object page is specified with annotation @UI.identification.
    1. Scroll down and change the value of annotation @UI.identification: [ { position: } ] for element planetypeid. Choose a value that lies between the values of elements flightdate and price.

    2. Add the highlighted code:

      Code Snippet
      Copy code
      Switch to dark mode
      1234567
      @UI.lineItem: [ { position: 60 , importance: #MEDIUM } ] planetypeid;
  3. Activate the metadata extension.

    1. Press Ctrl + F3 to activate the metadata extension.

Task 3: Provide a Value Help

In the data model projection for your service, use existing CDS view I_CurrencyStdVH to define a value help for the field CurrencyCode.

Steps

  1. Edit the definition of the projection view ( Z##_C_Flight). Annotate the view element CurrencyCode with annotation @Consumption.valueHelpDefinition: [{ }]. Use I_CurrencyStdVH as the value for the subannotation entity.name and Currency as the value for the subannotation entity.element.

    Note

    Currency is the name of the key element of CDS view I_CurrencyStdVH.
    1. Open the definition of CDS view entity Z##_C_FLIGHT where ## is your group number.

    2. Before view element CurrencyCode, add the following code:

      Code Snippet
      Copy code
      Switch to dark mode
      1234
      @Consumption.valueHelpDefinition: [{ entity.name: 'I_CurrencyStdVH', entity.element: 'Currency' }]
  2. Activate the projection view definition.

    1. Press Ctrl + F3 to activate the projection view definition.

Task 4: Verify the Result

Restart the preview of the OData UI Service and verify the changes to the user interface.

Steps

  1. Restart the preview of the OData Service.

    1. Close the browser window or browser tab that contains the preview.

    2. Open your service binding. In the Entity Set and Associations list on the right-hand side, first choose entity Flight and then choose Preview....

  2. On the report list page, verify that the buttons Create and Delete have disappeared.

    1. Proceed as you have done in previous exercises.

  3. Verify that there are two selection fields at the top of the report list page. Test their functionality.

    Hint

    Be aware that the selection fields support the entry of multiple values and ranges.
    1. Enter a value in the selection field Airline ID (for example: "LH") and choose Go.

    2. Repeat with other values.

  4. For any data set, navigate to the object page. Verify that the Delete button has disappeared.

    1. Proceed as you have done in previous exercises.

  5. Verify that field Plane Type is displayed after field Flight Date and before field Flight Price.

    1. Proceed as you have done in previous exercises.

  6. Switch to change mode and check the order of the fields.

Log in to track your progress & complete quizzes