on 02-08-2019 5:38 AM
I have a Fiori service which has lots of views which share many of the same properties
Currently i am repeating the same boiler plate annotations over and over again
In my Fiori Annotations .cds file i would like to be able to create my own type and then apply it where ever
from this
annotate cats.StocksView1 with @( // header-level annotations
..
}){
// element-level annotations
ID @UI.Hidden;
CreatedAt @UI.Hidden;
Modified @UI.Hidden;
}
...
annotate cats.StocksViewN with @( // header-level annotations
..
}){
// element-level annotations
ID @UI.Hidden;
CreatedAt @UI.Hidden;
Modified @UI.Hidden;
}
to
"@myAnno": {
ID @UI.Hidden;
CreatedAt @UI.Hidden;
Modified @UI.Hidden;
}
annotate cats.StocksView1 with @(myAnno)
..
annotate cats.StocksViewN with @(myAnno)
I am guessing the answer is probably in the help somewhere, but anyone know off the top off their heads if it could work like that?
Hi John 🙂
just add the common annotations to an own entity or type from which others can inherit:
type managed {
createdAt : DateTime @UI.Hidden;
}
entity Books : managed {}
See the docs.
Seems the predefined CDS types already cover what you want to achieve. Take a look at the 'managed' and the 'cuid' types in 'node_modules/@sap/cds/common.cds'. Refer to them with
using { managed, cui } from @sap/cds/common;
Available with @sap/cds >=3, documentation soon to come.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thinking about it I think i should have started with an Abstract Entity, then used that as a base type for all the child entities
abstract entity MyTable @(
UI: {
Identification: [{ $Type: 'UI.DataField', Value: name }],
PresentationVariant:
{ SortOrder: [ {$Type: 'Common.SortOrderType', Property: Field1, Descending: false}],
RequestAtLeast: [Field1,Field2]
},
LineItem: [
{$Type: 'UI.DataField', Value: Field3, "@UI.Importance":#High},
{$Type: 'UI.DataField', Value: Field4, "@UI.Importance": #High},
{$Type: 'UI.DataField', Value: Field5, "@UI.Importance": #High},
) {
key Field1 : String(3);
Field2: localized String;
Field3: localized String;
...
}
then I can use
entity Child1 : MyTable {
FieldN: String(40) @title: '{i18n>FieldN}';
}
entity Child2 : MyTable
just saw it used here via foundations reuse example
https://github.com/SAP/cloud-samples-catalog/blob/master/db/model.cds
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cheers Christian
You answered my question correctly, and you definitely pointed me in the right direction, I think however i may have asked it wrongly, I'll try again
In my scenario i have 10+ views, the views share a lot of the same characteristics, not all and the data is different,
All the views need the same UI Annotations, example below being a @UI.PresentationVariarnt and LineItem
UI: {
PresentationVariant:
{ SortOrder: [ {$Type: 'Common.SortOrderType', Property: Field1, Descending: false}],
RequestAtLeast: [Field1,Field2]
},
LineItem: [
{$Type: 'UI.DataField', Value: Field3, "@UI.Importance":#High},
{$Type: 'UI.DataField', Value: Field4, "@UI.Importance": #High},
{$Type: 'UI.DataField', Value: Field5, "@UI.Importance": #High},
..
]
}
rather than repeating that code many times like below, or doing f
annotate Child11 with @(
UI: {
PresentationVariant:
{ SortOrder: [ {$Type: 'Common.SortOrderType', Property: Field1, Descending: false}],
RequestAtLeast: [Field1,Field2]
}
...
}
..
annotate Child1N with @(
UI: {
PresentationVariant:
{ SortOrder: [ {$Type: 'Common.SortOrderType', Property: Field1, Descending: false}],
RequestAtLeast: [Field1,Field2]
}
...
}
is there a way to do this without repetition?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
11 | |
8 | |
8 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.