68
SAP Logistics Business Network, Global Track and Trace Option Basic Modeling Tutorial Document Version: LBN 2.0 2021-03-20 Tutorial PUBLIC

Basic Modeling Tutorial - help.sap.com

  • Upload
    others

  • View
    15

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Basic Modeling Tutorial - help.sap.com

SAP Logistics Business Network, Global Track and Trace OptionBasic Modeling Tutorial

Document Version: LBN 2.0 – 2021-03-20

Tutorial

PUBLIC

Page 2: Basic Modeling Tutorial - help.sap.com

2

TABLE OF CONTENTS

1 BASIC MODELING – A STEP BY STEP TUTORIAL ....................................................................31.1 About this Document .....................................................................................................................31.2 Target Audience ............................................................................................................................31.3 Documentation References ...........................................................................................................31.4 Supplied Models ............................................................................................................................3

2 OVERVIEW ...................................................................................................................................43 PREREQUISITES .........................................................................................................................54 LESSON 1: PARCEL TRACKING .................................................................................................64.1 Step 1: Create a GTT Model ..........................................................................................................64.2 Step 2: Define a Basic Model .........................................................................................................94.3 Step 3: Deploy Your Model .......................................................................................................... 184.4 Step 4: Create and Assign a Business Role ................................................................................. 204.5 Step 5: Provide the Data .............................................................................................................. 254.6 Step 6: Track Parcel Deliveries in the GTT App ........................................................................... 274.7 Step 7: Add Information Blocks to the Object Page ...................................................................... 314.8 Step 8: Add Parcel Items to the Object Page ............................................................................... 344.9 Step 9: Add Event Entities ........................................................................................................... 404.10 Step 10: Track Events in the GTT App ......................................................................................... 454.11 Step 11: Report a Planned Event from the GTT App .................................................................... 504.12 Step 12: Create a Business Rule ................................................................................................. 534.13 Step 13: Report an Unplanned Event from the GTT App .............................................................. 624.14 Summary ..................................................................................................................................... 66

5 CREATE A GTT MODEL BASED ON A TEMPLATE MODEL .................................................... 67

Page 3: Basic Modeling Tutorial - help.sap.com

3

1 BASIC MODELING – A STEP BY STEP TUTORIAL

1.1 About this Document

This document guides you through the process of creating a basic Global Track and Trace (GTT) model fromscratch, in a step-by-step manner.

Before you start working through this document, ensure that you have the most recent version of thisdocument that is available from the SAP Help Portal at:

https://help.sap.com/gtt

1.2 Target Audience

A Modeling Expert or Solution Administrator who needs to create, define, deploy, and maintain GTT modelsin the global track and trace option for SAP Logistics Business Network.

1.3 Documentation References

Throughout this tutorial, references are made to other GTT documentation, such as the GTT AdministrationGuide and Onboarding Guide. The latest versions of all GTT documentation are available from the SAP HelpPortal at:

https://help.sap.com/gtt

1.4 Supplied Models

Various steps in Lesson 1 mention supplied models, for example:

· Model_1_base· Model_2_details· Model_3_items· Model_4_events

The Create a GTT Model Based on a Template Model section also mentions an example GTT model that iscreated from a shipment template model.

All these models are provided for reference only and are available from:

https://github.com/SAP-samples/gtt-tutorial-models/

Page 4: Basic Modeling Tutorial - help.sap.com

4

2 OVERVIEW

The global track and trace option for SAP Logistics Business Network is a solution used to capture, process,and store tracking information about business processes. It provides real-time transparency of the executionof those processes. You can query a tracked process and display its retrieved data from end to end.

Before you can track and trace with the solution, a GTT model must be created to define the metadata of atracked process.

In this tutorial, you'll create a basic GTT model based on a parcel tracking application. The business processof the application is as follows:

· A parcel is delivered from a shipper to a receiver, which involves:o A courier picking up the parcel at the shipper location and delivering it to a distribution hub.o Another courier picking up the same parcel from the distribution hub, and delivering it to a receiver

location.

After completing this tutorial, you'll learn the following:

· How to define a GTT model to track process and event data, such as parcel ID, shipper/receiver nameand location, as well as shipping statuses like "picked up from sender."

· How to monitor the business process information tracked by the GTT model.· How to create a business rule for a GTT model to automatically trigger an action upon a certain

condition, for example, sending an email to a recipient when an unplanned event occurs.

Page 5: Basic Modeling Tutorial - help.sap.com

5

3 PREREQUISITES

To perform the tasks outlined in this tutorial, you must have fulfilled the following:

· You must have access to a running GTT solution.

For detailed onboarding procedures, refer to the Onboarding Guide.

· In your GTT solution, you must have the Solution Administrator business role for accessing thefollowing apps: Metadata Modeling (MM), GTT Model Management (GMM), Manage Business Roles(MBR), and Manage GTT Users (MGU).

NoteThe MM and GMM apps can also be accessed by the Modeling Expert role.The MGU app can also be accessed by the User Administrator role.The MBR app can only be accessed by the Solution Administrator role.

Information on configuring business roles can be found in the Onboarding Guide: Configure IdentityAuthentication Service.

· Some steps use an external sender system such as Postman. To use any external sender system, youneed the credentials for a technical user to enable the connection between systems.

For more information on how to maintain a technical user, see the Onboarding Guide: Create aTechnical User and Maintain the Technical User for Your Company.

· Some steps describe tasks involving business rules. To perform these tasks, the relevant business rulesconfiguration must be made in the Onboarding Assistance appà System Integration tab.

Detailed configuration steps are described in the Onboarding Guide: Maintain System IntegrationInformation in Onboarding Assistance App.

Page 6: Basic Modeling Tutorial - help.sap.com

6

4 LESSON 1: PARCEL TRACKING

4.1 Step 1: Create a GTT Model

Before you can track a parcel delivery process in the GTT app, you must first create a GTT model to definethe process and events that you want to track. This is done in the Metadata Modeling (MM) app, also knownas the Global Track and Trace plugin for SAP Web IDE.

A GTT model is in a specific GTT project associated with a specific namespace. In this tutorial, you'll createa GTT project with the namespace: com.sap.gtt.app.tutorial.parceltracking

Concepts

The first decision in any modeling work is which mode to use, standard (the default) or simple.

· Standard mode defines your GTT model with complete model and UI layout information. A standard-mode GTT model consists of several model files to define the model itself, the services, and the UIannotations, separately.

· Simple mode simplifies modeling by defining your GTT model with basic layout information in only onemodel file. Simple mode does not support all modeling functionality. For more information, see theCreating and Deploying GTT Models guide: Creating and Deploying Modelsà Simple and StandardModes.

Throughout this tutorial, we use standard mode.

Procedure

To create a GTT model from scratch, proceed as follows:

1. Log in to the SAP Web IDE for Full-Stack Development application.2. If you haven't already done so, enable the Global Track and Trace plugin on the Features page as

follows:a) In the Tools menu, choose Preferences.b) In the left-hand pane, select Features.c) In the Features view displayed in the right pane, scroll down, switch on Global Track and Trace and

choose Save.

Page 7: Basic Modeling Tutorial - help.sap.com

7

d) Reload the SAP Web IDE Full-Stack application by refreshing the browser.

3. Choose Fileà Newà Project from Template.

A wizard appears as follows:

4. On the Template Selection page, choose Global Track and Trace in the Category list, and choose Next.5. On the Basic Information page, type tutor1 as the project name for your GTT project and choose Next.

Page 8: Basic Modeling Tutorial - help.sap.com

8

6. On the Project Customization page, make the following entries:o Mode: Standardo Template: None

We'll create the parcel tracking model from scratch, so don't use any template.

o Namespace: com.sap.gtt.app.tutorial.parceltracking

The namespace must be unique in a GTT tenant.

NoteIf you specify a different namespace here, then in all the model CDS files that you will edit in proceeding steps, youmust replace the occurrences of com.sap.gtt.app.tutorial.parceltracking with the namespace youspecify.

o Version: 1.0.0o Process Name: Parcel Trackingo Dependency: Noneo Description: Parcel Tracking Tutorial Model

7. Choose Finish.

Result

A GTT project that has a parcel tracking model in it. Your screen should look like the following:

Page 9: Basic Modeling Tutorial - help.sap.com

9

4.2 Step 2: Define a Basic Model

Previously, you created a GTT project that has a GTT model in it.

In this step, you'll start defining your model by specifying the type of business process and the fields that youwant to track.

Concepts

· CDS Definition Language

The language used in GTT modeling is the CDS Definition Language. CDS defines entity-relationshipmodels with annotations. Such models can be easily interpreted by compilers and thus transferred toother formats.

NoteFor more information on the CDS Definition Language, see the Creating and Deploying GTT Models guide:Modeling Language Guideà Introduction to CDS.

· GTT Model Files

A standard-mode GTT model consists of several CDS model files. Each CDS model file is a readabletext file so you can use a text editor to view its contents.

To define your parcel tracking model in this tutorial, you need to edit the following model files that wereautomatically created for you:

File Purpose

tutor1Model.cds Defines the metadata model (tracked process and events) for theparcel tracking application.

tutor1Service.cds Exposes the necessary entities as a service.

tutor1UI.cds Provides the UI annotations for SAP Fiori elements for the parceltracking application.

tutor1WriteService.cds Exposes the necessary entities as a service for processes andevents ingestion, which allows you to use model-specific restAPIs.

A swagger file will be generated based on the definitions in thisfile. You can then view the swagger file in the GTT ModelManagement app.

NoteThis tutorial does not involve tasks to use model-specific rest APIs, so you don't need to edit thetutor1WriteService.cds file. You can leave the file as is. The steps for editing this file are provided for reference only.

Page 10: Basic Modeling Tutorial - help.sap.com

10

· GTT Core Model and Application Model

A GTT core model includes generic fields that are not relevant to specific business, for example, trackingID, tenant, event status, etc. The core model is predefined and you are not able to modify it.

The model you are defining is called a GTT application model. An application model extends the coremodel with user-defined entities and fields. If you want to use some entities and fields that are alreadydefined in the core model, you have to inherit them in your application model.

When you deploy your application model, the inherited core model entities and fields are automaticallyappended to your run-time GTT model.

NoteFor more information on core model details and different types of application models, see the Creating andDeploying GTT Models guide: Modeling Language Guideà GTT Metadata Model with CDS.

· Entities and Fields

A GTT model contains multiple entities. For example, within your process you can have:

o an entity for a tracked process type, ando several entities for the planned or unplanned event types that you want to track.

For each entity, you can add fields to define the type of data that you want to track.

Page 11: Basic Modeling Tutorial - help.sap.com

11

Procedure

To define your GTT application model, proceed as follows:

1. In the SAP Web IDE for Full-Stack Development application, also called the Metadata Modeling app

(MM app) for GTT, choose Development ( ).2. In the left-hand pane, navigate to the Workspace folder.3. Under Workspaceà tutor1à model, double-click the tutor1Model.cds file.

As shown in the following screenshot, the file is opened in a text editor in the right-hand pane. Note thatthe first line, also known as a script, is the namespace you specified when creating your GTT project.

Page 12: Basic Modeling Tutorial - help.sap.com

12

4. In the right-hand text editor, copy and paste the following scripts after the first line of the tutor1Model.cdsfile:

using com.sap.gtt.core.CoreModel;

context ParcelTrackingModel {

//Tracked process "Parcel Tracking"entity BaseParcelTrackingProcess {

parcelId : String(10) @title:'Parcel ID';shipper : String(20) @title: 'Shipper';shipperlocation : String(255) @title: 'Shipper Location';receiver : String(20) @title: 'Receiver';receiverlocation : String(255) @title: 'Receiver Location';

@CoreModel.KeepStatusSequence: trueshippingStatus : String(50) @title:'Shipping Status' enum {

notStarted='01' @title: 'Not Started'; //Parcel process not startedpickingCompleted='02' @title: 'Picking Completed'; //Goods picked upreceived='03' @title: 'Received'; //Goods received

} default '01';};

@CoreModel.StatusProperties : ['shippingStatus']@CoreModel.Indexable : trueentity ParcelTrackingProcess : CoreModel.TrackedProcess,

BaseParcelTrackingProcess{};entity ParcelTrackingProcessForWrite : CoreModel.TrackedProcessForWrite,

BaseParcelTrackingProcess{};entity AllTrackedProcessForParcelTrackingProcess : CoreModel.AllTrackedProcess,

BaseParcelTrackingProcess{};

//Data provision from SAP ERP or other external sender [email protected]: #inboundMessage@SAP_EM.applicationObjectType: 'OB_PT_00'@SAP_EM.primaryTrackingIdType: 'PAR_00'entity ParcelTrackingProcessInbound as projection on ParcelTrackingProcess {

@SAP_EM.fieldName : 'PAL_ID'parcelId,

@SAP_EM.fieldName : 'SHIPPER'shipper,

@SAP_EM.fieldName : 'SHIP_LOC'shipperlocation,

@SAP_EM.fieldName : 'RECEIVER'receiver,

@SAP_EM.fieldName : 'REC_LOC'receiverlocation,

@SAP_EM.fieldName : 'SHIP_STAT'shippingStatus

};};

NoteYou can ignore red errors which appear typically on using and service statements. The editor cannot interpretthese specific GTT statements so it shows them as errors.

Page 13: Basic Modeling Tutorial - help.sap.com

13

o The using statement in the first line is used to reference the GTT core model.o The context ParcelTrackingModel statement prefixes names of nested definitions with

ParcelTrackingModel.o The entity BaseParcelTrackingProcess section defines a tracked process entity

BaseParcelTrackingProcess and its properties.

For example, the first propertyparcelId : String(10) @title:'Parcel ID';

defines a field parcelId. Its data type is string. The field length is at most 10 characters. On thetrack and trace user interface, the field title is Parcel ID.

o entity ParcelTrackingProcess : CoreModel.TrackedProcess,BaseParcelTrackingProcess{};

defines a tracked process entity ParcelTrackingProcess, which inherits fields from theCoreModel.TrackedProcess and BaseParcelTrackingProcess entities.

o entity ParcelTrackingProcessForWrite : CoreModel.TrackedProcessForWrite,BaseParcelTrackingProcess{};

defines a tracked process entity ParcelTrackingProcessForWrite, which is used by rest API writeservice. It inherits fields from the CoreModel.TrackedProcessForWrite andBaseParcelTrackingProcess entities.

o entity AllTrackedProcessForParcelTrackingProcess : CoreModel.AllTrackedProcess,BaseParcelTrackingProcess{};

defines an entity for including different process types. This entity can be used to achieve someadvanced features such as tracking packing hierarchy, etc.

NoteFor detailed information on how to define entities, see the Creating and Deploying GTT Models guide: ModelingLanguage Guideà Language Elementsà Entity Definitions.

NoteThe process and field names defined in the GTT model can be displayed in different supported languages in thetrack and trace apps. To make that possible, you need to adjust your model. For example, in the tutor1Model.cdsfile, instead of using @title:'Parcel ID', write @title:'{@i18n>Parcel_ID}'. Then in the i18n files forspecific languages, provide the exact values for {@i18n>Parcel_ID}.

In this tutorial, we do not explain the i18n files, used to support languages on the UI. If you need information on this,see the Creating and Deploying GTT Models guide: Creating and Deploying Modelsà Multi-Language Support.

o The //Data provision part is used for receiving tracking data from a connected ERP system or anexternal sender system. This is needed if standard iFlows are used. For more information, see:

https://api.sap.com/package/SAPGlobalTrackTraceInterfaceTrackedProcessesandEventMessages?section=Overview

NoteThe values of @SAP_EM.applicationObjectType and @SAP_EM.primaryTrackingIdType must be unique ina GTT tenant.

Page 14: Basic Modeling Tutorial - help.sap.com

14

5. Under Workspaceà tutor1à service, open the tutor1Service.cds file, and add the following scripts to it:using com.sap.gtt.app.tutorial.parceltracking.ParcelTrackingModel;using com.sap.gtt.core.CoreServices.TrackedProcessService;using com.sap.gtt.core.CoreModel;

service ParcelTrackingService @extends: TrackedProcessService {

@CoreModel.UsageType: #[email protected]: trueentity ParcelTrackingProcess as projection on

ParcelTrackingModel.ParcelTrackingProcess excluding {tenant, name, trackedProcessType,lastProcessedEvent,CreatedByUser, CreationDateTime,LastChangedByUser, LastChangeDateTime

};

entity AllTrackedProcessForParcelTrackingProcess as projection onParcelTrackingModel.AllTrackedProcessForParcelTrackingProcess;};

o If used, the using statements must be written in the following order from top to bottom:· <application>Service, e.g. ParcelTrackingService· <application>Model, e.g. ParcelTrackingModel· CoreServices· CoreModel· CoreType

o The @extends: statement is used to extend your application service from the core service.o The entity … as projection on statement defines the association or composition in the service

the same way as they are defined in the model.

NoteFor more information on how to define services, see the following sections in the Creating and Deploying GTTModels guide:

· Modeling Language Guideà GTT Metadata Model with CDSà Core Model Detailsà Core Model

· Modeling Language Guideà GTT Metadata Model with CDSà Application Model Detailsà DeliveryApplication Modelà Delivery Application Service

Page 15: Basic Modeling Tutorial - help.sap.com

15

6. Under Workspaceà tutor1à service, open the tutor1UI.cds file, and add the following scripts to it:using com.sap.gtt.app.tutorial.parceltracking.ParcelTrackingService;

//Annotations for Parcel Trackingannotate ParcelTrackingService.ParcelTrackingProcess with @(

Common: {Label: 'Parcel Tracking',SemanticKey: [ parcelId ],FilterExpressionRestrictions: [],

},UI: {

Identification: [{Value: parcelId},

],HeaderInfo: {

TypeName: 'Parcel Delivery',TypeNamePlural: 'Parcel Deliveries',Title: {

Label: 'Parcel Tracking',Value: parcelId

},Description: {

Label: 'Parcel Tracking',Value: description

}},SelectionFields: [

parcelId],PresentationVariant: {

SortOrder: [{Property: parcelId, Descending: true}

]},

},Capabilities: {

Insertable: false, Updatable: false, Deletable: false,FilterRestrictions: {

NonFilterableProperties: [shipper,description,sender,receiver,shippingstatus,shipperlocation,shipperlocation

]},SortRestrictions: {

NonSortableProperties: [shipper,description,sender,receiver,shippingstatus,shipperlocation,shipperlocation

]},

Page 16: Basic Modeling Tutorial - help.sap.com

16

SearchRestrictions: {Searchable: false

}},

) {};

//Line items for lists on Overview pageannotate ParcelTrackingService.ParcelTrackingProcess with @UI.LineItem: [

{Value: parcelId},{Value: shipper},{Value: receiver},{Value: shippingStatus}

];

UI annotations are used to display the tracked process and events data in the GTT app UI. The GTT apphas an Overview page to show a list of tracked process instances in a tabular format, and an Objectpage to show details of each tracked process instance. The above scripts mainly define the UI layout onthe Overview page. You will define more UI annotations for the Object page later.

The UI annotations used in the above scripts are described below:

o annotate <TrackedProcess> with @ <annotations> defines the UI layout.o The common block defines the overall behavior for the Overview page:

· Label is the process title shown on the page.· SemanticKey is an array of field names that will be displayed in bold font in the processes list.

o The UI block defines what the Overview page looks like:· Identification is a list of field names that uniquely identify the tracked process.· HeaderInfo defines the header of the processes list table on the Overview page.· SelectionFields define a list of field names that are initially visible as search filters on the

Overview page.· PresentationVariant defines how the result is displayed in the processes list table. A GTT

model only allows SortOrder, which is a list of sort criteria for the default sorting.o In the capabilities block:

· Insertable, Updatable, and Deletable define whether a process instance can be inserted,updated, or deleted from the UI. In a GTT model these values must be false.

· FilterRestrictions defines restrictions on the filter capabilities of the processes list. A GTTmodel only allows NonFilterableProperties, which is a list of field names that cannot be usedas filter criteria.

· SortRestrictions defines restrictions on the sort capabilities of the processes list. A GTTmodel only allows NonSortableProperties, which is a list of field names that cannot be usedas sort criteria.

o annotate <TrackedProcess> with @UI.LineItem: [<set of fields>]defines the appearanceof the processes list table on the Overview page. Value is the field name that appears in the listtable.

NoteFor more information on UI annotations, see the Creating and Deploying GTT Models guide: Modeling LanguageGuideà GTT Metadata Model with CDSà UI Annotations.

Page 17: Basic Modeling Tutorial - help.sap.com

17

7. (This step is optional. If you don't want to use model-specific rest APIs, you can skip this step.)

Under Workspaceà tutor1à service, open the tutor1WriteService.cds file, and add the following scriptsto it:

using com.sap.gtt.app.tutorial.parceltracking.ParcelTrackingModel;using com.sap.gtt.core.CoreServices.TrackedProcessWriteService;using com.sap.gtt.core.CoreModel;

service ParcelTrackingWriteService @extends: TrackedProcessWriteService {

entity ParcelTrackingProcess as projection onParcelTrackingModel.ParcelTrackingProcessForWrite excluding {

shippingStatus}actions {

@Swagger.POSTaction parcelTrackingProcess(@Swagger.parameter: 'requestBody'

parcelTrackingProcess: ParcelTrackingProcess) returns String;};

};

The settings in this file expose the entities as a service for post and event ingestion, which allows you touse the model-specific rest APIs. You can use rest APIs to provide data to the model.

8. Choose Fileà Save All.

Result

Now in your parcel tracking application, you have defined the basic entities, exposed the required services,and defined the UI layout.

For reference, you can see and compare your model with the supplied model: Model_1_base.

Page 18: Basic Modeling Tutorial - help.sap.com

18

4.3 Step 3: Deploy Your Model

Previously, you defined a basic parcel tracking model. The model is still in design time.

In this step, you'll deploy your model to the run time repository and activate it. When a GTT model isactivated, it starts tracking the defined processes and events.

Concepts

The deployment of a GTT model includes the following three successive steps.

1. Compile checks the model definition for errors. A model with compilation errors cannot be deployed.You must fix the errors before deploying it.

2. Deploy sends the model metadata, together with the core model metadata it references, from designtime to run time.

3. Activate sets the model status to Active, which means the model now starts tracking process andevents.

Optionally, you can Preview a compiled model in the MM app. The preview imitates what the model looks inthe GTT app, thus helping you debug your model before it is deployed. Note that the preview uses mockdata so you don't need to provide data for it.

Procedure

To deploy your model, proceed as follows:

1. In the left-hand pane, right-click the tutor1 project folder and choose Deployà Compile GTT Model.

This starts the compilation. You see a message "Model compiled" when it completes.

If errors are found, a message box pops up showing error details. To continue, your model must containno errors.

2. Right-click the tutor1 project folder and choose Deployà Preview GTT Model.

This opens a preview window in a web browser window, which allows you to see how your GTT modellooks and feels like in the GTT app. Note that the preview shows mock data only. For more informationon the GTT app see the Tracking and Tracing Guide.

Page 19: Basic Modeling Tutorial - help.sap.com

19

3. Now you are satisfied with your model, you can deploy it to the runtime repository. To deploy the model,right-click the tutor1 project folder and choose Deployà Activate GTT Model.

This starts the deployment process. Successive messages pop up in the upper-right corner of the MMapp window. When the deployment completes, you see a message "Model … has been deployed". You

can also choose the (Console) icon on the right edge of the window to open the Console to observethe deployment progress, as shown below:

NoteYou can also skip the previous steps and directly choose Activate GTT Model. The system then runs compilation,deployment, and activation in a single step.

Result

When the deployment completes, the Console displays the message "Model … has been deployed". Thestatus of your deployed model is now Active. This means that your model is now available in your tenant fortracking.

As we’ll see later, any messages it receives in the appropriate format will be tracked (stored) and then canbe queried.

Page 20: Basic Modeling Tutorial - help.sap.com

20

4.4 Step 4: Create and Assign a Business Role

Previously, you deployed and activated your parcel tracking model to start tracking.

To monitor the business process data tracked by the model, you must be assigned to a specific businessrole that is authorized to track models that have a namespace starting with a particular pattern.

In this step, you'll first use the Manage Business Roles (MBR) app to create a Parcel Tracking Specialistrole, which is authorized to track models with a namespace com.sap.gtt.app.tutorial*. Then you'll assign therole to yourself in the Manage GTT Users (MGU) app.

Procedure

To create and assign a Parcel Tracking Specialist role, proceed as follows:

1. Log on to your GTT solution.2. On the SAP Fiori Launchpad, click the Manage Business Roles app tile.

NoteThe above screenshot is for reference. Depending on your user authorization, your Fiori Launchpad may containfewer app tiles. The Manage Business Roles app is visible to a user with the Solution Administrator role.

Page 21: Basic Modeling Tutorial - help.sap.com

21

3. In the left-hand Business Roles pane, choose the + icon.

Page 22: Basic Modeling Tutorial - help.sap.com

22

4. In the Add a new business role pane, specify the following and choose Save.o Business Role: Parcel Tracking Specialisto User By: Solution Ownero Role Identifier: tutorial

After the role is saved, the system automatically generates the value of the field Accessible TrackedProcess Type(s) for you with the following pattern:

Accessible Tracked Process Types = com.sap.gtt.app.<Role_Identifier>*

This enables users with this business role to access tracked processes with a namespace ofcom.sap.gtt.app.<Role_Idenditifier>*, with the above setting, com.sap.gtt.app.tutorial*.

Remember the namespace of your parcel tracking model is com.sap.gtt.app.tutorial.parceltracking,so the user with this role can then access the data tracked by the parcel tracking model.

o Description: A user responsible for tracking parcel deliveries based on tutorialmodel

5. If business users from invited solution participants shall as well be able to track instances of this trackedprocess type, a separate business role needs to be created with “used By: Solution participants”. To dothat, just repeat steps 3 and 4 but select Solution Participants for Used By.

Page 23: Basic Modeling Tutorial - help.sap.com

23

6. On the title bar of the window, choose the (Home) icon to go to the SAP Fiori Launchpad.

7. On the Fiori Launchpad, click the Manage GTT Users app tile.

8. In Users list, find your user. You may use the Search box to narrow down the list.

9. In the row for your user, choose the (Edit) icon.

Page 24: Basic Modeling Tutorial - help.sap.com

24

10. In the Edit User dialog box, under Business Role, select Parcel Tracking Specialist, and choose Save.

11. On the title bar of the window, choose the icon and sign out.

The new business role assignment takes effect the next time you logon.

Result

The Parcel Tracking Specialist role has been created and assigned to you, which means you are now able totrack models with a namespace of com.sap.gtt.app.tutorial* in the GTT app.

For more information on how to create and maintain GTT business roles, see the Administration Guide: UserManagement by Solution Administrator.

Page 25: Basic Modeling Tutorial - help.sap.com

25

4.5 Step 5: Provide the Data

Previously, you have deployed and activated your parcel tracking model to start the tracking and beenassigned with the appropriate role for tracking the model in the GTT app.

GTT checks the content of all messages it receives, such as the business information that an actual eventhas occurred, and routes the messages appropriately. The first time that GTT routes a tracked processmessage to an activated model, it creates a tracked process instance in the unique namespace in the tenant.

In this step, you'll provide the first data to your model so that a corresponding tracked process instance iscreated. In productive usage, the data for a tracked process often is sent to GTT from other systems such asSAP ERP. In this tutorial, you'll send the data directly to your GTT system using an external sender tool,such as Postman. However, you can use any tool that supports the sending of HTTP requests.

Concepts

The following methods can be used to provide data from an external sender tool:

· API: Global Track and Trace Interface: Tracked Processes and Event Messages(https://api.sap.com/package/SAPGlobalTrackTraceInterfaceTrackedProcessesandEventMessages?section=Overview)

Throughout this tutorial, we use this method to provide the data.

· Model-specific rest API: uses the rest APIs exposed by the tutor1WriteService.cds file in your model.

Procedure

1. Start the external sender tool, such as Postman.2. For security reasons, you need to provide proper authorization for your message including a technical

user for your GTT system. For this, you may need to contact your system administrator.

Note that the email ID used by your technical user must be different to that used by your business role.

NoteFor information on technical users, see the Onboarding Guide: Create a Technical User and Maintain the TechnicalUser for Your Company.

3. Send the following HTTP request to your GTT system.o HTTP Method: POSTo URL: Ask your system administrator for the URL to send a request.

For example: https://<server_address>[:port]/<space>/v1/process

o Request Body: The following code represents a message for your tracked process containing thebusiness data of a parcel delivery process specified using the attributes you defined earlier in yourbasic model.

In this case, the process is for shipper “John Brown” to send receiver “Fred Smith” parcel ID“0000001” from shipper location "No.88 XXX Avenue" to receiver location “No. 66 YYY Road” usingtracking ID "1234567890" between “11Dec2018” and “30Dec2019”. The shipping status is "01” (notstarted).

Note that the value of the applicationObjectType identifies this message as being for your trackedprocess instance. This must be the same as the @SAP_EM.applicationObjectType value in yourtutor1Model.cds file.

Page 26: Basic Modeling Tutorial - help.sap.com

26

Copy and paste the following JSON scripts but replace <EM_System_ID> with the actual system IDset up by your system administrator.

{"applicationObjects": {

"applicationSystem": "<EM_System_ID>","applicationObjectType": "OB_PT_00","applicationObjectId": "PT_NO_1","parameters": [{

"parameterName": "PAL_ID","parameterIndex": "0000000000","parameterValue": "0000001"

}, {"parameterName": "SHIPPER","parameterIndex": "0000000000","parameterValue": "John Brown"

}, {"parameterName": "SHIP_LOC","parameterIndex": "0000000000","parameterValue": "No.88 XXX Avenue"

}, {"parameterName": "RECEIVER","parameterIndex": "0000000000","parameterValue": "Fred Smith"

}, {"parameterName": "REC_LOC","parameterIndex": "0000000000","parameterValue": "No.66 YYY Road"

}, {"parameterName": "SHIP_STAT","parameterIndex": "0000000000","parameterValue": "01"

}],

"trackingIds": [{"trackingIdType": "PAR_01","trackingId": "0000001"

},{"trackingIdType": "PO_NO","trackingId": "1234567890","validFrom": "2018-12-11T12:00:00+01:00","validTo": "2019-12-30T12:00:00+01:00","timeZone": "CET"

}]}

}

ResultBased on the tracked process message you sent, the first data for your tracked process, GTT has used youractivated model to create an instance of your tracked process in your unique namespace in your tenant.

For reference, you can see and compare your JSON scripts with the supplied model_1_data.json file inModel_1_base.

Page 27: Basic Modeling Tutorial - help.sap.com

27

4.6 Step 6: Track Parcel Deliveries in the GTT App

Previously, you have deployed a parcel tracking model and provided data to it. The first time the modelreceives the business data it is defined to track, it creates a tracked process instance. From then on, you canfind your tracked process instance in the GTT app.

In this step, you'll use the GTT app to monitor the process instance that has been tracked by your model.

Remember that you were already assigned the role, Parcel Tracking Specialist. Otherwise, you are not ableto track this model in the GTT app.

Procedure

1. Log on to your GTT solution.2. On the SAP Fiori Launchpad, click the Track Processes and Objects tile to start the GTT app.

NoteThe above screenshot is for reference. Depending on your actual user authorization, your Fiori Launchpad maycontain fewer app tiles.

Page 28: Basic Modeling Tutorial - help.sap.com

28

3. In the Processes and Objects list, select Parcel Tracking that has the namespacecom.sap.gtt.app.tutorial.parceltracking.

4. In the upper-right corner of the Overview page, choose Go.

Optionally, you can use the Parcel ID search filter to narrow down your search and then choose Go.

Page 29: Basic Modeling Tutorial - help.sap.com

29

The parcel delivery that has been tracked by your model is listed on the Overview page, as shownbelow:

On the filter bar, you see only one search filter: Parcel ID. This was defined by the UI.SelectionFieldsstatement in tutor1UI.cds.

In the list table, you see 4 fields for each parcel delivery: Parcel ID, Shipper, Receiver, and ShippingStatus. These fields were defined in the process entity in your model.

By clicking the (Settings) icon above the table, you see more fields for the process, including thefields that were defined in the GTT core model and referenced by your parcel tracking model.

Page 30: Basic Modeling Tutorial - help.sap.com

30

5. In the search result, select the parcel delivery process.

You are directed to the process' Object page that includes a header 0000001 only, which is the value ofthe parcelId field and connected to the 'PAL_ID' SAP EM field in the tutor1Model.cds file. In thetutor1UI.cds file, parcelId is included in the UI.HeaderInfo block, which indicates that its value shouldbe shown as a header in the Object page.

Your screen looks like the following:

Page 31: Basic Modeling Tutorial - help.sap.com

31

4.7 Step 7: Add Information Blocks to the Object Page

Previously, you saw your parcel delivery process instance displayed on the Overview and Object pages inthe GTT app. The Object page only shows a header.

In this step, you'll enhance your model to show more data on the Object page, by adding two new blocks, fora header and detailed information. The blocks are controlled in the code by what are called facets.

Procedure

1. In the MM app, choose Development ( ) in the left-hand pane and navigate to the tutor1 folder underWorkspace.

2. In the tutor1UI.cds file, add the following scripts above //Line items for lists on Overview page,and save the file:

annotate ParcelTrackingService.ParcelTrackingProcess with @(UI.HeaderFacets: [

{$Type: 'UI.ReferenceFacet', Target: '@UI.FieldGroup#SenderInfo'}],UI.FieldGroup#SenderInfo: {

Label: 'Sender',Data: [

{Value: logicalSenderSystem},{Value: trackingId},{Value: trackingIdType}

]},UI.FieldGroup#Locations: {

Label: 'Location',Data: [

{Value: shipperlocation},{Value: receiverlocation}

]},

UI.Facets: [{

$Type: 'UI.CollectionFacet',ID: 'BusinessProcess',Label: 'Business Process',Facets: [

{$Type: 'UI.CollectionFacet',ID: 'DetailInfo',Label: 'Detailed Information',Facets: [

{$Type: 'UI.ReferenceFacet', Target:'@UI.FieldGroup#Locations'},

]},

]},

]);

The above scripts define the structure of the Object page, including

o In the header facet: Sender System, Tracking ID, Tracking ID Typeo Under Detailed Information section: Shipper Location, Receiver Location

Page 32: Basic Modeling Tutorial - help.sap.com

32

The UI annotations are described below:

o annotate <TrackedProcess> with @ <annotations> defines the UI layout.o The UI.HeaderFacets block contains field groups to be displayed in the header of the Object page.

$Type is always UI.ReferenceFacet, and Target is a reference to the field group.o The UI.FieldGroup block defines an ordered collection of data fields with a label for the group.o The UI.Facets block defines the structure of the Object page, and the field groups included in the

structure.

NoteFor more information, see the Creating and Deploying GTT Models guide: Modeling Language Guideà GTTMetadata Model with CDSà UI Annotations.

3. As before, in the left-hand pane, right-click the tutor1 project folder and choose Deployà Compile GTTModel.

To proceed, your model must contain no errors.

4. You can immediately test your updates by, again as before, right-clicking the tutor1 project folder andchoosing Deployà Preview GTT Model.

This opens a browser window that previews the Overview page of the GTT app with mock data. ThePreview window looks like the following:

5. On the Overview page, select any of the parcel IDs.

Page 33: Basic Modeling Tutorial - help.sap.com

33

Result

In the Preview window, you are directed to the process' Object page that displays the process details thatyou have just defined, as shown below:

In a later step, you'll deploy the model and track parcel deliveries in the GTT app with real data.

For reference, you can see and compare your model with the supplied model: Model_2_details.

Page 34: Basic Modeling Tutorial - help.sap.com

34

4.8 Step 8: Add Parcel Items to the Object Page

Previously, you added some process information to the Object page.

In this step, you'll add a table to the Object page to list the parcel items that are delivered in the targetprocess.

Procedure

1. In the MM app, choose Development ( ) in the left-hand pane and navigate to the tutor1 folder underWorkspace.

2. Modify the tutor1Model.cds file as follows:o Add the lines highlighted in red to the context ParcelTrackingModel {} block, as shown below:

context ParcelTrackingModel {

//Parcel items dataentity ParcelTrackingItem {

key parcel : Association to one ParcelTrackingProcess;key parcelTrackingItem : String(6) @title:'Parcel Tracking Number';productId : String(50) @title:'Product ID';descritption : String(255) @title: 'Description';producttype : String(50) @title: 'Product Type';quantity : Integer @title: 'Quantity';uom : String(20) @title: 'UoM';sourcesystem : String(20) @title: 'Source System';sender : String(20) @title: 'Sender';

};

This block defines the data fields to be tracked for the parcel items.

o Add the lines highlighted in red to the entity BaseParcelTrackingProcess {} block, as shownbelow:entity BaseParcelTrackingProcess {

parcelId : String(10) @title:'Parcel ID';shipper : String(20) @title: 'Shipper';shipperlocation : String(255) @title: 'Shipper Location';receiver : String(20) @title: 'Receiver';receiverlocation : String(255) @title: 'Receiver Location';

@CoreModel.KeepStatusSequence: trueshippingStatus : String(50) @title:'Shipping Status' enum {

notStarted='01' @title: 'Not Start'; //Parcel process not startedpickingCompleted='02' @title: 'Picking Completed'; //Goods picked upreceived='03' @title: 'Received'; //Goods received

} default '01';items : Composition of many ParcelTrackingItem on

items.parcel = $self;};

This associates the parcel items entity to the process entity.

Page 35: Basic Modeling Tutorial - help.sap.com

35

o Add the data provisioning part for parcel items, as highlighted in red below (don't forget the commaafter shippingStatus):

//Data provision from SAP ERP or other external sender [email protected]: #inboundMessage@SAP_EM.applicationObjectType: 'OB_PT_00'@SAP_EM.primaryTrackingIdType: 'PAR_00'entity ParcelTrackingProcessInbound as projection on ParcelTrackingProcess {

@SAP_EM.fieldName : 'PAL_ID'parcelId,

@SAP_EM.fieldName : 'SHIPPER'shipper,

@SAP_EM.fieldName : 'SHIP_LOC'shipperlocation,

@SAP_EM.fieldName : 'RECEIVER'receiver,

@SAP_EM.fieldName : 'REC_LOC'receiverlocation,

@SAP_EM.fieldName : 'SHIP_STAT'shippingStatus,

@SAP_EM.itemizedEntity: 'ParcelTrackingItemInbound'items : redirected to ParcelTrackingItemInbound

};

@CoreModel.UsageType: #inboundMessage@SAP_EM.itemized: trueentity ParcelTrackingItemInbound as projection on ParcelTrackingItem {

@SAP_EM.fieldName : 'PARCEL_ITEM'parcelTrackingItem,

@SAP_EM.fieldName : 'PROD_ID'productId,

@SAP_EM.fieldName : 'DESC'descritption,

@SAP_EM.fieldName : 'PROD_TYPE'producttype,

@SAP_EM.fieldName : 'QUANTITY'quantity,

@SAP_EM.fieldName : 'UOM'uom,

@SAP_EM.fieldName : 'SOUR_SYS'sourcesystem,

@SAP_EM.fieldName : 'SENDER'sender

};};

NoteFor detailed information on how to define entities, see the Creating and Deploying GTT Models guide: ModelingLanguage Guideà Language Elementsà Entity Definitions.

Page 36: Basic Modeling Tutorial - help.sap.com

36

3. In the tutor1Service.cds file, add the lines highlighted in red to the service ParcelTrackingServiceblock, as shown below, to expose the ParcelTrackingItem entity as a service:

entity AllTrackedProcessForParcelTrackingProcess as projection onParcelTrackingModel.AllTrackedProcessForParcelTrackingProcess;

//expose parcel items in service layerentity ParcelTrackingItem as projection on

ParcelTrackingModel.ParcelTrackingItem;

NoteFor more information on defining services, see the following sections in the Creating and Deploying GTT Modelsguide:

· Modeling Language Guideà GTT Metadata Model with CDSà Core Model Detailsà Core Model

· Modeling Language Guideà GTT Metadata Model with CDSà Application Model Detailsà DeliveryApplication Modelà Delivery Application Service

4. Modify the tutor1UI.cds file as follows:o Add the lines highlighted in red to the UI.Facets: block, as shown below:

UI.Facets: [{

$Type: 'UI.CollectionFacet',ID: 'BusinessProcess',Label: 'Business Process',Facets: [

{$Type: 'UI.CollectionFacet',ID: 'DetailInfo',Label: 'Detailed Information',Facets: [

{$Type: 'UI.ReferenceFacet', Target:'@UI.FieldGroup#Locations'},

]},{

$Type: 'UI.CollectionFacet',ID: 'ParcelItems',Label: 'Parcel Items',Facets: [

{$Type: 'UI.ReferenceFacet', Target:'items/@UI.LineItem'},

]},

]},

]);

This adds the parcel items table to the Detailed Information section on the Object page.

Page 37: Basic Modeling Tutorial - help.sap.com

37

o Add the following lines at the end of the file:annotate ParcelTrackingService.ParcelTrackingItem with @(

Capabilities: {Insertable:false, Updatable:false, Deletable:false,FilterRestrictions: {

NonFilterableProperties: [quantity,uom,sourcesystem,sender

]},SortRestrictions: {

NonSortableProperties: [quantity,uom,sourcesystem,sender

]},SearchRestrictions: {

Searchable: false}

},) {};

// Line Item for Parcel Items on Object pageannotate ParcelTrackingService.ParcelTrackingItem with @UI.LineItem: [

{Value: productId},{Value: descritption},{Value: producttype},{Value: quantity},{Value: uom},{Value: sourcesystem},{Value: sender}

];

· The Capabilities lines define the overall behavior for parcel items.· annotate <entity> with @UI.LineItem: [<set of fields>]defines the appearance of the

list table on the Object page. Value is the field name that appears in the list table.

NoteFor more information on UI annotations, see the Creating and Deploying GTT Models guide: Modeling LanguageGuideà GTT Metadata Model with CDSà UI Annotations.

Page 38: Basic Modeling Tutorial - help.sap.com

38

5. (This step is optional. If you don't want to use model-specific rest APIs, you can skip this step.)

In the tutor1WriteService.cds file, add the lines highlighted in red to the serviceParcelTrackingWriteService block, as shown below, to expose the ParcelTrackingItem entity as awrite service:

service ParcelTrackingWriteService @extends: TrackedProcessWriteService {

entity ParcelTrackingProcess as projection onParcelTrackingModel.ParcelTrackingProcessForWrite excluding {

shippingStatus}actions {

@Swagger.POSTaction parcelTrackingProcess(@Swagger.parameter: 'requestBody'

parcelTrackingProcess: ParcelTrackingProcess) returns String;};

entity ParcelTrackingItem as projection on ParcelTrackingModel.ParcelTrackingItemexcluding {

parcel};

};

This exposes the parcel items entity as a write service, which allows you to use the model-specific restAPIs.

6. Choose Fileà Save All.7. In the left-hand pane, right-click the tutor1 project folder and choose Deployà Compile GTT Model.

To proceed, your model must contain no errors.

8. As before, right-click the tutor1 project folder and choose Deployà Preview GTT Model.

This opens a browser window that previews the Overview page of the GTT app with mock data.

9. On the Object page, select any of the parcel IDs.

Page 39: Basic Modeling Tutorial - help.sap.com

39

Result

In the Preview window, you are directed to the process' Object page. Your page now includes a Parcel Itemslist table, as shown below:

You'll deploy the model in a later step and track parcel deliveries in the GTT app with real data.

For reference, you can see and compare your model with the supplied model: Model_3_items.

Page 40: Basic Modeling Tutorial - help.sap.com

40

4.9 Step 9: Add Event Entities

Previously, you have enabled the display of various process information on the Object page.

In this step, you'll add event entities to your model to define the event types and data that the model willtrack.

You'll define the entities for the following events:

· Picked up from shipper (planned event)· Arrived at distribution hub (planned event)· Delayed (unplanned event)

Concepts

· Planned Event

an incident that corresponds to a step in a tracked process that typically occurs in the future with aforeseen date and time, and if applicable, a foreseen location.

· Unplanned Event

an incident that corresponds to a step in a tracked process that is not planned upfront.

Procedure

1. In the MM app, choose Development ( ) in the left-hand pane and navigate to the tutor1 folder underWorkspace.

2. Modify the tutor1Model.cds file as follows:o Add the following scripts above the @CoreModel.StatusProperties : ['shippingStatus'] line:

@CoreModel.PlannedEvents: [{eventType: PickedUpFromShipperEvent, matchLocation: false},{eventType: ArrivedAtDistributionHubEvent, matchLocation: false},

]

@CoreModel.AdmissibleUnplannedEvents: [{eventType: DelayedEvent}

]

These lines define the event types for planned and unplanned events, respectively.

Page 41: Basic Modeling Tutorial - help.sap.com

41

o Add the entities for the 3 events above the //Data provision from SAP ERP or other externalsender systems line, as shown below:

//Event for "Picked Up from Shipper"entity BasePickedUpFromShipperEvent {

courier : String(50);};@UI.HeaderInfo.Title.Label: 'Picked Up From Shipper Event'@SAP_EM.eventCode: {Code: 'PICK_UP', Text: 'Picked Up From Shipper Event', Type:

'PLANNED'}@CoreModel.UpdateStatus: [

{pathToStatus: 'ParcelTrackingProcess.shippingStatus', newValue: '02'}]@CoreModel.Indexable: falseentity PickedUpFromShipperEvent: CoreModel.Event, BasePickedUpFromShipperEvent{};entity PickedUpFromShipperEventForWrite: CoreModel.EventForWrite,

BasePickedUpFromShipperEvent{};annotate PickedUpFromShipperEvent with {

location @CoreModel.ObjectIdentifierType: #customerLocation;};

//Event for "Arrived at Distribution Hub"entity BaseArrivedAtDistributionHubEvent {

courier : String(50);};@UI.HeaderInfo.Title.Label: 'Arrived At Distribution Hub Event'@SAP_EM.eventCode: {Code: 'ARRI_AT', Text: 'Arrived At Distribution Hub Event',

Type: 'PLANNED'}@CoreModel.UpdateStatus: [

{pathToStatus: 'ParcelTrackingProcess.shippingStatus', newValue: '03'}]@CoreModel.Indexable: falseentity ArrivedAtDistributionHubEvent: CoreModel.Event,

BaseArrivedAtDistributionHubEvent{};entity ArrivedAtDistributionHubEventForWrite: CoreModel.EventForWrite,

BaseArrivedAtDistributionHubEvent{};annotate ArrivedAtDistributionHubEvent with {

location @CoreModel.ObjectIdentifierType: #customerLocation;};

//Event for "Delayed" - unplanned evententity BaseDelayedEvent {

// empty here};@UI.HeaderInfo.Title.Label: 'Delayed'@SAP_EM.eventCode: {Code: 'DELAY', Text: 'Delayed', Type: 'UNPLANNED'}@CoreModel.Indexable: falseentity DelayedEvent: CoreModel.Event, BaseDelayedEvent{};entity DelayedEventForWrite: CoreModel.EventForWrite, BaseDelayedEvent{};annotate DelayedEvent with {

location @CoreModel.ObjectIdentifierType: #customerLocation;};

· In the above scripts, the [email protected]: [{pathToStatus: 'ParcelTrackingProcess.shippingStatus', newValue: '02'}]Defines that after the tracked event is reported, the shipping status will be automatically updatedto the specified newValue '02' (Goods picked up).

NoteFor detailed information on how to define entities, see the Creating and Deploying GTT Models guide: ModelingLanguage Guideà Language Elementsà Entity Definitions.

Page 42: Basic Modeling Tutorial - help.sap.com

42

3. In the tutor1Service.cds file, add the lines highlighted in red inside the serviceParcelTrackingService block, as shown below, to expose the newly-added event entities as a service:

entity AllTrackedProcessForParcelTrackingProcess as projection onParcelTrackingModel.AllTrackedProcessForParcelTrackingProcess;

//expose parcel items in service layerentity ParcelTrackingItem as projection on

ParcelTrackingModel.ParcelTrackingItem;

//expose events in service layerentity PickedUpFromShipperEvent as projection on

ParcelTrackingModel.PickedUpFromShipperEvent;entity ArrivedAtDistributionHubEvent as projection on

ParcelTrackingModel.ArrivedAtDistributionHubEvent;entity DelayedEvent as projection on ParcelTrackingModel.DelayedEvent;

NoteFor more information on defining services, see the following sections in the Creating and Deploying GTT Modelsguide:

· Modeling Language Guideà GTT Metadata Model with CDSà Core Model Detailsà Core Model

· Modeling Language Guideà GTT Metadata Model with CDSà Application Model Detailsà DeliveryApplication Modelà Delivery Application Service

Page 43: Basic Modeling Tutorial - help.sap.com

43

4. In the tutor1UI.cds file, add the lines highlighted in red to the UI.Facets: block, as shown below:

UI.Facets: [{

$Type: 'UI.CollectionFacet',ID: 'BusinessProcess',Label: 'Business Process',Facets: [

{$Type: 'UI.CollectionFacet',ID: 'DetailInfo',Label: 'Detailed Information',Facets: [

{$Type: 'UI.ReferenceFacet', Target:'@UI.FieldGroup#Locations'},

]},{

$Type: 'UI.CollectionFacet',ID: 'ParcelItems',Label: 'Parcel Items',Facets: [

{$Type: 'UI.ReferenceFacet', Target:'items/@UI.LineItem'},

]},{

$Type: 'UI.CollectionFacet',ID: 'Events',Label: 'Event Messages',Facets: [

{$Type: 'UI.ReferenceFacet', Target:'processEvents/@UI.LineItem#GenericEvents'},

]},

]},

]);

This adds the event messages table to the Detailed Information section on the Object page. The tablelists planned and unplanned events tracked by the target process instance.

NoteFor more information on UI annotations, see the Creating and Deploying GTT Models guide: Modeling LanguageGuideà GTT Metadata Model with CDSà UI Annotations.

Page 44: Basic Modeling Tutorial - help.sap.com

44

5. (This step is optional. If you don't want to use model-specific rest APIs, you can skip this step.)

In the tutor1WriteService.cds file, add the lines highlighted in red inside the serviceParcelTrackingWriteService block, as shown below, to expose the event entities as a write service:

entity ParcelTrackingItem as projection on ParcelTrackingModel.ParcelTrackingItemexcluding {

parcel};

entity PickedUpFromShipperEvent as projection onParcelTrackingModel.PickedUpFromShipperEventForWrite

actions {@Swagger.POSTaction pickedUpFromShipperEvent(@Swagger.parameter: 'requestBody'

pickedUpFromShipperEvent: PickedUpFromShipperEvent) returns String;};

entity ArrivedAtDistributionHubEvent as projection onParcelTrackingModel.ArrivedAtDistributionHubEventForWrite

actions {@Swagger.POSTaction arrivedAtDistributionHubEvent(@Swagger.parameter: 'requestBody'

arrivedAtDistributionHubEvent: ArrivedAtDistributionHubEvent) returns String;};

entity DelayedEvent as projection on ParcelTrackingModel.DelayedEventForWriteactions {

@Swagger.POSTaction delayedEvent(@Swagger.parameter: 'requestBody' delayedEvent:

DelayedEvent) returns String;};

This exposes the event entities as a write service, which allows you to use the model-specific rest APIs.

6. Choose Fileà Save All.7. Right-click the tutor1 project folder and choose Deployà Activate GTT Model.

NoteIf the event code DELAY, PICK_UP, or ARRI_AT already exists in another model in the same tenant, you mayreceive a warning message. In that case, continue by choosing Yes.

Result

For reference, you can see and compare your model with the supplied model: Model_4_events.

Page 45: Basic Modeling Tutorial - help.sap.com

45

4.10 Step 10: Track Events in the GTT App

Previously, you have defined tracked events, including planned and unplanned events, in your parceltracking model.

In this step, as before you'll use an external sender tool, such as Postman, to send event data, and thenmonitor the tracked events in the GTT app.

Procedure

1. Start the external sender tool, such as Postman.2. For security reasons, you need to provide proper authorization for your message including a technical

user for your GTT system. For this, you may need to contact your system administrator.

Note that the email ID used by your technical user must be different to that used by your business role.

NoteFor information on technical users, see the Onboarding Guide: Create a Technical User and Maintain the TechnicalUser for Your Company.

3. Send the following HTTP request.o HTTP Method: POSTo URL: Ask your system administrator for the URL to send requests.

For example: https://<server_address>[:port]/<space>/v1/process

Page 46: Basic Modeling Tutorial - help.sap.com

46

o Request Body:

Copy and paste the following JSON scripts but replace <EM_System_ID> with the actual system IDset up by your system administrator.

{"applicationObjects": {

"applicationSystem": "<EM_System_ID>","applicationObjectType": "OB_PT_00","applicationObjectId": "PT_NO_4","parameters": [{

"parameterName": "PAL_ID","parameterIndex": "0000000000","parameterValue": "0000004"

}, {"parameterName": "SHIPPER","parameterIndex": "0000000000","parameterValue": "John Brown"

}, {"parameterName": "SHIP_LOC","parameterIndex": "0000000000","parameterValue": "No.88 XXX Avenue"

}, {"parameterName": "RECEIVER","parameterIndex": "0000000000","parameterValue": "Fred Smith"

}, {"parameterName": "REC_LOC","parameterIndex": "0000000000","parameterValue": "No.66 YYY Road"

}, {"parameterName": "SHIP_STAT","parameterIndex": "0000000000","parameterValue": "01"

}, {"parameterName": "PARCEL_ITEM","parameterIndex": "0000000010","parameterValue": "000010"

}, {"parameterName": "PROD_ID","parameterIndex": "0000000010","parameterValue": "100000010"

}, {"parameterName": "DESC","parameterIndex": "0000000010","parameterValue": "Keyboard 101"

}, {"parameterName": "PROD_TYPE","parameterIndex": "0000000010","parameterValue": "Keyboard"

}, {"parameterName": "QUANTITY","parameterIndex": "0000000010","parameterValue": "1"

}, {"parameterName": "UOM","parameterIndex": "0000000010","parameterValue": "EA"

}, {"parameterName": "SOUR_SYS","parameterIndex": "0000000010","parameterValue": "X0M"

Page 47: Basic Modeling Tutorial - help.sap.com

47

}, {"parameterName": "SENDER","parameterIndex": "0000000010","parameterValue": "ABC"

}, {"parameterName": "PARCEL_ITEM","parameterIndex": "0000000011","parameterValue": "000011"

}, {"parameterName": "PROD_ID","parameterIndex": "0000000011","parameterValue": "100000011"

}, {"parameterName": "DESC","parameterIndex": "0000000011","parameterValue": "Brand Mouse"

}, {"parameterName": "PROD_TYPE","parameterIndex": "0000000011","parameterValue": "Mouse"

}, {"parameterName": "QUANTITY","parameterIndex": "0000000011","parameterValue": "2"

}, {"parameterName": "UOM","parameterIndex": "0000000011","parameterValue": "EA"

}, {"parameterName": "SOUR_SYS","parameterIndex": "0000000011","parameterValue": "X0M"

}, {"parameterName": "SENDER","parameterIndex": "0000000011","parameterValue": "ABC"

}],

"trackingIds": [{"trackingIdType": "PAR_04","trackingId": "0000004"

},{"trackingIdType": "PO_NO","trackingId": "1234567890","validFrom": "2018-12-11T12:00:00+01:00","validTo": "2019-12-30T12:00:00+01:00","timeZone": "CET"

}],"plannedEvents": [{

"eventCode": "PICK_UP","plannedBusinessTimestamp": "2019-12-01T12:00:00+01:00","plannedBusinessTimeZone": "CET","customIdentifier": "customID"

}]}

}

For reference, you can also find the above JSON scripts in the supplied model_4_data.json file inModel_4_events.

Page 48: Basic Modeling Tutorial - help.sap.com

48

4. On the SAP Fiori Launchpad, click the Track Processes and Objects tile to start the GTT app.5. In the Processes and Objects list, select Parcel Tracking that has a namespace

com.sap.gtt.app.tutorial.parceltracking:6. In the upper-right corner of the Overview page, choose Go, or use the Parcel ID search filter to narrow

down your search and then choose Go.

The parcel deliveries that have been tracked by your model are listed on the Overview page.

7. On the search page, select a parcel tracking process.

Page 49: Basic Modeling Tutorial - help.sap.com

49

Result

You are directed to the process' Object page. The page contains some information in the header facet, someinformation in the Detailed Information section, and a Parcel Items table, which were added in the previoussteps. Also, you see an Event Messages table at the bottom that shows the events that you have just sent.

Page 50: Basic Modeling Tutorial - help.sap.com

50

4.11 Step 11: Report a Planned Event from the GTT App

Previously, you sent process and event data from an external sender system.

In this step, you'll report a planned event from the GTT app.

Procedure

1. On the SAP Fiori Launchpad, click the Track Processes and Objects tile to start the GTT app.2. In the Processes and Objects list, select Parcel Tracking that has a namespace

com.sap.gtt.app.tutorial.parceltracking.3. In the upper-right corner of the Overview page, choose Go.4. On the search page, select a parcel tracking process.

The process' Object page opens.

5. In the Event Messages list, select the radio button beside the event name, and choose Report PlannedEvent.

Page 51: Basic Modeling Tutorial - help.sap.com

51

6. In the Report Planned Event dialog box, specify the actual business time and its time zone, as you like,and choose OK.

Results

1. You will receive a message: Event message has been submitted to the system and is in process

Page 52: Basic Modeling Tutorial - help.sap.com

52

2. The actual business time of Picked Up from Shipper will be updated to the time you reported and theevent status changes to Reported. If the event message is not updated, choose the Refresh button atthe upper-right corner of the page. It may take some time before you see the refreshed result.

You screen looks like the following:

You can also click the row for the newly reported event to navigate to the event's details page, as shownbelow:

Page 53: Basic Modeling Tutorial - help.sap.com

53

4.12 Step 12: Create a Business Rule

Previously, you built a parcel tracking model, and monitored the data tracked by the model.

In this step, you'll create a business rule for your model. A business rule is used to automatically trigger anaction when certain events are processed for a tracked process. You'll define a rule that expresses thefollowing logic:

· If a delayed event occurs (the event type contains "Delayed"), then send an email to notify related users.

Concepts

The GTT solution includes an event-to-action engine, a tool that automatically triggers actions if certainevents are processed for a tracked process or object.

You can create business rules in the GTT Model Management (GMM) app to meet your business needs.Your business rules are applied by the event-to-action engine. In your rules, you define the conditions whichtrigger actions and what those actions are. Supported actions include sending emails to users or updatingbackend systems.

Once a business rule is defined and activated in a deployed GTT model, whenever an actual event occursthat matches the conditions defined in the rule, it triggers the corresponding action.

For more information, see the Managing Business Rules guide.

Procedure

To create and apply a business rule, proceed as follows:

1. On the SAP Fiori Launchpad, click the GTT Model Management tile to start the GMM app.

Page 54: Basic Modeling Tutorial - help.sap.com

54

2. On the search page, select your parcel tracking model.

The search page lists the GTT models that have been deployed to the tenant, sorted by Changed Onfrom newest to oldest. You can also use the Search box to find your target model.

3. Select the Rule Services tab.

The tab lists the rule services that you can use for your model.

4. Select the rule service ActionEmailNotification.

Page 55: Basic Modeling Tutorial - help.sap.com

55

5. Choose the + icon above the Rules table.

6. In the New Rule dialog box, enter delayed_notification as the rule name, and choose Create.

Page 56: Basic Modeling Tutorial - help.sap.com

56

7. On the New Rule page, specify hit policy and description as follows:o Hit Policy: First Matcho Description: Notify Delayed event

8. Choose the (Decision Table Setting) icon above the decision table, define the following in theDecision Table Settings dialog box, and choose Apply:o Condition Expression: eventType of the DelayedEvent of a ParcelTrackingProcess

When specifying a condition, make sure you always reference the root processParcelTrackingProcess.

o Fixed Operator: contains

Page 57: Basic Modeling Tutorial - help.sap.com

57

9. Above Decision Table, choose Add Rowà Insert First.

Page 58: Basic Modeling Tutorial - help.sap.com

58

10. In the new row, click inside each table cell and enter the following:o Under If: 'Delayed'o Under message: 'A delayed event has occurred. Parcel ID:' + parcelId of the

ParcelTrackingProcess

This is the content of the email to be sent, in which parcelId of the ParcelTrackingProcess is avariable that will be replaced by an actual parcel ID.

o Under subject: 'Event Delayed'

This is the subject of the email to be sent. You can also insert variables to the subject.

o Under recipients: '<email_address_of_recipient>'

This the email address of the notification recipient. If you want to send emails to multiple recipients,separate the email addresses with semicolons.

Your screen looks like the following:

Page 59: Basic Modeling Tutorial - help.sap.com

59

11. In the upper-right corner of the New Rule page, choose Save.

12. In the upper-right corner of the New Rule page, choose Activate and confirm your choice in theconfirmation dialog box.

Page 60: Basic Modeling Tutorial - help.sap.com

60

Result

The new business rule is created for your parcel tracking model, and the rule status changes to Active, whichmeans the rule is now in working status. Each time a delayed event is processed, this rule triggers emails tobe sent to the specified recipients.

If you go back to the previous Rule Services page by clicking the (Back) icon twice, as shown below,

Page 61: Basic Modeling Tutorial - help.sap.com

61

You see the Active Rules/All Rules column for the ActionEmailNotification rule service is 1/1, which means abusiness rule has been created and it's active.

In the next step, you'll report a delayed event from the GTT app. After that, since your business rule isalready active, the recipient you specified in the rule will then receive an email notifying him or her that adelayed event has occurred.

Page 62: Basic Modeling Tutorial - help.sap.com

62

4.13 Step 13: Report an Unplanned Event from the GTT App

Previously, you defined a business rule in your parcel tracking model to trigger email notification when adelayed event occurs.

In this step, you'll report an unplanned event (a delay) in the GTT app and check the action (email sent)triggered by the business rule.

Procedure

1. On the SAP Fiori Launchpad, click the Track Processes and Objects tile to start the GTT app.2. In the Processes and Objects list, select Parcel Tracking that has a namespace

com.sap.gtt.app.tutorial.parceltracking.3. In the upper-right corner of the Overview page, choose Go.4. On the search page, select a parcel tracking process.

The process' Object page opens.

5. On the upper-right part of the Event Messages list, choose Report Unplanned Event.

Page 63: Basic Modeling Tutorial - help.sap.com

63

6. In the Report Unplanned Event dialog box, select Delayed for Event, and specify actual business timeand its time zone as you like, and choose OK.

Page 64: Basic Modeling Tutorial - help.sap.com

64

Results

1. You will receive a message: Event message has been submitted to the system and is in process

2. A new event Delayed will be added to the Event Messages list. Its event status is Unplanned. If theevent message is not updated, choose the Refresh button at the upper-right corner of the page. It maytake some seconds (minimum) until the event message is processed.

You screen looks like the following:

Page 65: Basic Modeling Tutorial - help.sap.com

65

You can also click the row for the newly reported event to navigate to the event's details page, as shownbelow:

Remember that you have created a business rule in the previous step. The recipient you specified in thatrule then receives an email notifying that a delayed event has occurred. Open the mailbox and you'll find themail with the predefined subject "Event Delayed".

Page 66: Basic Modeling Tutorial - help.sap.com

66

4.14 Summary

Congratulations, you have completed this lesson!

In this lesson, you learnt how to:

· Model a parcel tracking application by defining a standard-mode GTT model in the MM app.· Deploy and activate the parcel tracking model in the MM app.· Create and assign a business role for monitoring the data tracked by the parcel tracking model.· Monitor the parcel tracking data in the GTT app.· Report planned and unplanned events for the parcel tracking process in the GTT app.· Create a business rule for the parcel tracking model in the GMM app to automatically trigger email

notification when a Delayed event occurs.

Page 67: Basic Modeling Tutorial - help.sap.com

67

5 CREATE A GTT MODEL BASED ON A TEMPLATE MODEL

Apart from creating a model from scratch, as described in this tutorial, you can also create a GTT modelbased on a template model. A template model is predefined to track common events and parameters in atypical tracking scenario, such as a shipment or an outbound delivery. You can enhance the template modelto meet your own business needs.

An enhanced GTT model created from a shipment template is available at:https://github.com/SAP-samples/gtt-tutorial-models/Model_shipment_enhancement

You can download the following from the site:

· A zip file that includes the enhanced GTT model created from a shipment template· a PDF document that describes the implementation steps needed to enhance the template model by

adding parameter, events, and changing display layouts. It also shows the steps for defining Event toAction business rules.

After you download the zip file, import the enhanced GTT model into your SAP Web IDE account and followthe implementation steps.

Page 68: Basic Modeling Tutorial - help.sap.com

www.sap.com/contactsap

© 2020 SAP SE or an SAP affiliate company. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company. The information contained herein may bechanged without prior notice.

Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors. National product specifications may vary.

These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP or its affiliated companies shall not be liablefor errors or omissions with respect to the materials. The only warranties for SAP or SAP affiliate company products and services are those that are set forth in the express warranty statementsaccompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and othercountries. All other product and service names mentioned are the trademarks of their respective companies.

Please see https://www.sap.com/about/legal/trademark.html for additional trademark information and notices.