cancel
Showing results for 
Search instead for 
Did you mean: 

CAP action doesn't return data properly when called using a custom action

David21
Explorer
0 Kudos
102

Hello everyone,

I'm using CAP(Node.js) with Fiori elements. I have a cap action that returns a string : 

this.on('CapAction', entity, async req => {
            return "TEST"
        });
I have also added a custom action using extension point & my requirement is such that i need to call the CAP action when the user click on custom button. Custom action's handler look like this : NewQS.PNG
Now the the CAP action handler is being called and in the network tab of developer tools it's returning : 

HTTP/1.1 200 OK
odata-version: 4.0
content-type: application/json;odata.metadata=minimal

{"@odata.context":"../$metadata#Edm.String","value":"TEST"}

But inside my custom handler the result variable shows :

d {oModel: T, sPath: '/TestService(ID=6f76d291-9e2e-423a-bd16-1c7b7…true)/TestService.CapAction(...)', bForceRefresh: false, sDeepPath: '', oBinding: c, …}

And the string "TEST" isn't being returned anywhere in this object. Any ideas how i can get the returned value ?

Accepted Solutions (1)

Accepted Solutions (1)

Willem_Pardaens
Product and Topic Expert
Product and Topic Expert

The return value of the 'invokeAction()' function is an ODataV4Context on which the 'getObject()' function will return the data object.

See: https://sapui5.hana.ondemand.com/1.135.0/#/api/sap.ui.model.odata.v4.Context%23methods/getObject

So in your code you can do

this.editFlow
  .invokeAction(sActionName, oParameters)
  .then(result => {
    const data = result?.getObject()
    console.log(data?.value)
  }

 

David21
Explorer
0 Kudos
Appreciate the answer

Answers (0)