Skip to Content
0
Apr 09 at 11:52 AM

annotations fiori preview

74 Views

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?

Attachments

444.png (17.6 kB)
888.png (106.1 kB)