Let's have a look at the common.cds
file and the annotations in there. At the beginning, we see:
using riskmanagement as rm from '../db/schema';
// Annotate Risk elements
annotate rm.Risks with {
ID @title : 'Risk';
title @title : 'Title';
owner @title : 'Owner';
prio @title : 'Priority';
descr @title : 'Description';
miti @title : 'Mitigation';
impact @title : 'Impact';
}
Copy codeIt's referring to the definitions of the schema.cds
file that defines the Risks
and Mitigations
entities. Then it annotates the Risk
entity with numerous texts. These should be in a translatable file normally, but for now, we will keep them here. These texts are used as labels in form fields and column headers by SAP Fiori elements.
Next, take a look at the app/risks/annotations.cds
file:
using RiskService from '../../srv/risk-service';
// Risk List Report Page
annotate RiskService.Risks with @(UI : {
HeaderInfo : {
TypeName : 'Risk',
TypeNamePlural : 'Risks',
Title : {
$Type : 'UI.DataField',
Value : title
},
Description : {
$Type : 'UI.DataField',
Value : descr
}
},
SelectionFields : [prio],
Identification : [{Value : title}],
// Define the table columns
LineItem : [
{Value : title},
{Value : miti_ID},
{Value : owner},
{
Value : prio,
Criticality : criticality
},
{
Value : impact,
Criticality : criticality
},
],
});
Copy code
NoteYou will find the code block without page break a few pages later.
This file defines the content of the work list page and the object page, to which you are navigated, when you select a line in the work list.
The SelectionFields
section defines which of the properties are exposed as search fields in the header bar above the list, in this case prio
is the only explicit search field.
From the LineItem
section all the columns and their order of the work list are derived. While in most cases the columns are defined by Value:
followed by the property name of the entity, in the case of prio
and impact
there’s also Criticality
, which for now you can disregard, but keep it in mind in case you go to the later modules. It currently adds a diamond icon right left of the fields. You can just ignore it.
The next section defines the content of the object page:
// Risk Object Page
annotate RiskService.Risks with @(UI : {
Facets : [{
$Type : 'UI.ReferenceFacet',
Label : 'Main',
Target : '@UI.FieldGroup#Main',
}],
FieldGroup #Main : {Data : [
{Value : miti_ID},
{Value : owner},
{
Value : prio,
Criticality : criticality
},
{
Value : impact,
Criticality : criticality
}
]},
});
Copy codeThis section defines a single facet, a ReferenceFacet
, of the field group FieldGroup#Main
. This field group just shows up as a form. The properties of the Data
array within FieldGroup#Main
determine the fields in the form:
The last part of the common.cds
file is the most complicated one:
annotate rm.Risks with {
miti @(Common : {
//show text, not id for mitigation in the context of risks
Text : miti.descr,
TextArrangement : #TextOnly,
ValueList : {
Label : 'Mitigations',
CollectionPath : 'Mitigations',
Parameters : [
{
$Type : 'Common.ValueListParameterInOut',
LocalDataProperty : miti_ID,
ValueListProperty : 'ID'
},
{
$Type : 'Common.ValueListParameterDisplayOnly',
ValueListProperty : 'descr'
}
]
}
});
}
Copy codeWithout these lines, you would see the id of the mitigations from the miti
field, in both the list and the object page:
By introducing the annotations for the miti
property, instead of just displaying the original value of miti
, that is, the ID, the UI shows its description
property. The subsequent part ValueList
introduces a value help for miti
that you can see on the object page in its edit mode. The value help takes the id as an input parameter and again displays the description
parameter.