cancel
Showing results for 
Search instead for 
Did you mean: 

annotations fiori preview

0 Kudos

Hello,

I am trying to learn CAP and Fiori Elements. I have created the simplest service.

db/schema.csd

namespace db;

entity Todos {
    key Id: Integer;
    description: String;
    completed: Boolean;
}

And I have loaded some mock data (db/data/db-Todos.csv)

Id;description;completed
101;Shopping for groceries;false
102;Walk the dog;true
103;Clean up the garage;fale

I have created the service (srv/service.cds)

using {db} from '../db/schema';

service TodoService {
    entity Todos as projection on db.Todos;
}

annotate TodoService.Todos with @( 
    UI: {
        HeaderInfo  : {
            $Type : 'UI.HeaderInfoType',
            TypeName : 'Todo',
            TypeNamePlural : 'Todos',
        },
        SelectionFields  : [
            completed
        ],
        LineItem  : [
            { Value: Id, Label: 'Id' },
            { Value: description, Label: 'Description' },
            { Value: completed, Label: 'Completed' }
        ],
    }
);

When I do "cds watch" it works fine, I can both get the odata and do the "preview fiori"

Then I have created the "srv/service.js" to implement the handler "on" and return a json

const cds = require('@sap/cds')

module.exports = cds.service.impl (function(){
    
    this.on('READ','Todos', ()=>{
        const data = [
            {
                "Id": 101,
                "description": "Shopping for groceries",
                "completed": false
            },
            {
                "Id": 999,
                "description": "Walk the dog",
                "completed": true
            },
            {
                "Id": 103,
                "description": "Clean up the garage",
                "completed": true
            }
        ]

        return data
    })
})

now I can still get the odata, but the fiori preview is not working any more

I don't understand why the fiori preview is not working. The json returned by the Odata service looks exactly the same.

Anybody knows why is this happening?

Accepted Solutions (1)

Accepted Solutions (1)

gregorw
Active Contributor
0 Kudos

Please check the network traffic when using the standard app without the custom implementation. You will see that it requests also count how many entries are contained in the entity. Check how I solved it in srv/customer-material-service.js#L66.

0 Kudos

you are right, works perfectly.

danke schön

ale_biagi
Product and Topic Expert
Product and Topic Expert
0 Kudos

I was facing the exact same problem and your solution just came in perfect!
Thank you so much Gregor!

Answers (0)