cancel
Showing results for 
Search instead for 
Did you mean: 

CAP - Call bound functions/actions from UI

former_member231229
Participant

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.

former_member231229
Participant
0 Kudos

Update:
After some tweaks, the action gets triggered.
I changed two things:

  • Remove the namespace from the service, so it can be referred directly via <service_name>
  • Removed the "Determining" tag from the DataFieldForAction annotation
  • For a better usability, added the "Inline" tag to the DataFieldForAction annotation

The result is now this:

Which raises another question...is there a way to automatically provide the input parameter? The user is clicking the "Approve" button right on the line of the element he/her wants to approve, so it does not make sense to ask again for something..

I did try to apply what I read here but it doesn't seem to work.

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member231229
Participant
0 Kudos

Second Update:
My question doesn't make all sense, or in any case there's a suitable workaround.
A bound action (as the name implies) is bound to its entity, and therefore we can find all the necessary keys in the url.

Working with CAP, is easy as:

const requestId = req.params[0]; // Index based

So, working and question closed 🙂

Best,
Roberto.