Skip to Content
1
May 16, 2020 at 10:01 AM

CAP - Call bound functions/actions from UI

710 Views

Hello all,
I am using NodeJs flavor of CAP to create a simple Approval scenario, in which the Manager can approve/reject requests forwarded by his employees.

I am currently banging my head on calling bound actions from Fiori UI (List Report/Object Page), as fiori complains about an "Unknown Operation".

Here is my service definition:

service PlanningService @(
    requires: 'authenticated-user',
    path: 'planning',
    impl: './handlers/planning-service.js'
)  {


    @(restrict : [        { grant : ['READ', 'WRITE'], to : 'manager', where : 'approver_ID = $user' },        { grant: ['WRITE'], to : 'admin'} ])
    entity MyApprovals as projection on db.AccessRequest 
        actions {
            action approveRequest() returns String;
            action rejectRequest() returns String;
    };
}

I would like to call "approveRequest" or "rejectRequest" from the UI, here is what I did in the annotation file (only UI.LineItem is here, for brevity):

annotate srv.PlanningService.MyApprovals with @(
  UI: {
        // Other annotation elements removed for brevity
        LineItem: [
            {$Type: 'UI.DataField', Value: initiator.eMail},
            {$Type: 'UI.DataField', Value: accessDate},
            {$Type: 'UI.DataField', Value: locationFloor.location.name},
            {$Type: 'UI.DataField', Value: locationFloor.name},
            {$Type: 'UI.DataField', Value: requestStatus, Criticality: severity},
            {
              $Type: 'UI.DataFieldForAction',              
// Not sure what to put here
Action: 'srv.PlanningService.EntityContainer/MyApprovals_approveRequest',
Label: 'Approve',
Determining: true }, {
$Type: 'UI.DataFieldForAction', // Not sure what to put here
Action: 'srv.PlanningService.EntityContainer/MyApprovals_rejectRequest',
Label: 'Reject', Determining: true
} ] } )

What I set in the Action tag is only the latest of 1000 tries I did...whatever I set there, Fiori complains.
Testing the action from a REST client works perfectly.

I was not able to find anything on the internet as an example...the only one I found is here: Github. Look at line 96 of the code, and the syntax is the very same I used.

Any hint anyone? It should be something straightforward, but I really cannot sort it out :)

Best,

Roberto.