cloud-sdk-js: Calling function import from SAP Cloud SDK returns an empty object

Describe the bug Calling a function import from SAP Cloud SDK returns an empty object, even though the call is successful. You can reproduce the issue by using the following git repository. https://github.com/miyasuta/sdk-function-import-test

To Reproduce Steps to reproduce the behavior:

  1. Develop a custom odata service which includes a function import.
  2. In a Cloud SDK app, generate an odata client using below command as explained here. sap-cloud-sdk generate-odata-client -i service-specification/ -o odata-client/
  3. Call the function import from the Cloud SDK app.
  4. When the function import gets called, it falls into then() block, meaning that the call was successful. However, the response object is empty.

Expected behavior Response object should be filled with returned data.

Screenshots Calling the OData function import directly image

Calling function import from Cloud SDK app (delivery data should be returned between {}) image

Used Versions:

  • node version via node -v: 12.16.1
  • npm version via npm -v: 6.14.4
  • SAP Cloud SDK version you used as dependency: 1.31.0

Code Examples My controller code is as below.

import { Controller, Get } from '@nestjs/common';
import { functionImports } from 'odata-client/catalog-service';


@Controller('get-delivery')
export class GetDeliveryController {
    @Get()
    getDeliveryInfo() {
        return new Promise((resolve, reject) => {
            functionImports.getDeliveryDate({})
            .execute({
                url: 'http://localhost:4004'                
            })
            .then(res => {
                resolve('Function call successful: ' + JSON.stringify(res))
            })
            .catch(error => {
                resolve('Error occurred: ' + JSON.stringify(error))
            })
        })
    }
}

Log file No error has occurred.

Additional context None

Please check the following points

  • [X ] Have you provided detailed description about your issue?
  • [X ] Have you shared all the necessary information to help the cloud-sdk developer reproduce the issue?
  • [ X] Have you provided the expected behaviour?
  • [ X] Have you attached some useful screenshots?
  • [ X] Have you provided the node/npm/cloud-sdk versions?
  • [ X] Have you shared your code snippets as a minial example?
  • Have you provided you log file or related error messages?
  • [ X] Have you searched for related issues on Stackoverflow or answers.sap.com?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (14 by maintainers)

Most upvoted comments

Hi @miyasuta, @gregorwolf, @zfrk,

We implemented the feature in @sap-cloud-sdk/odata-common: 2.3.0 to support the modification of the response data before deserialization.

Take the following response as an example:

{
  "d": {
    "GetAttachmentCount": {
      "AttachmentCount": 0
    }
  }
}

Now, you can pass dataAccessor function as a parameter to execute() to modify the response data before the deserialization:

functionImportsRequestBuilder.execute(
  destination,
  data => data.d.GetAttachmentCount
);

I hope it can help you solve the problem. Please re-open the issue if you have any further questions.

Best regards, Zhongpin Wang