cancel
Showing results for 
Search instead for 
Did you mean: 

Complex Queries for Side-by-Side SuccessFactors extension using SAP Cloud SDK (NodeJS)

0 Kudos

Hi All,

I am trying to create request builders using SAP Cloud SDK for calling Successfactors Odata APIs. I am facing issues with complex OData querying that includes $expand and maybe custom fields.

  1. https://xxxxxxxxxxxxx/odata/v2/WfRequest(11111L)?$expand=wfRequestUINav
    I created the request builder as below for the above api:
WfRequest.requestBuilder()
                .getByKey(11111)
                .select(
                    WfRequest.WF_REQUEST_UI_NAV
                )
                .execute({
                    destinationName: "sfapi"
                });

I am getting the below error:
OData get by key request failed!

So I modified the code by adding TO_ to WF_REQUEST_UI_NAV as below:

WfRequest.TO_WF_REQUEST_UI_NAV

but still getting the same error. So I thought it may be a custom field and changed the code as below:

const  WF_REQUEST_UI_NAV = WfRequest.customField('wfRequestUINav');

function getWFRequestsDetail() {
    return WfRequest
                .requestBuilder()
                .getByKey(11111)
                .select(
                    WF_REQUEST_UI_NAV
                )
                .execute({
                    destinationName: "sfapi"
                });
}

I got the below output, but not the expanded result:

{
  "wfRequestUINav": {
    "__deferred": {
      "uri": "https://api12preview.sapsf.eu/odata/v2/WfRequest(11111L)/wfRequestUINav"
    }
  }
}

Can anyone help in fixing this issue?

Thanks & Regards,

Harish

dhem
Active Participant
0 Kudos

Hi dhem ,

Yes, it is the same question. Thanks for your response. I tried to log the error using try-catch, but strangely it did not throw any stack error:

I am attaching the EDMX file however. This spec file is from https://api.sap.com/api/ECWorkflow/resource tenant. However, the tenant i am using is https://api12preview.sapsf.eu/odata/v2. I am unable to attach the spec file, but it can be found here: https://api.sap.com/api/ECWorkflow/overview

Can you please go through this & advise?

dhem
Active Participant

Thanks for attachting the edmx file, we will take a look at it and get back to you! Regarding logging the error: the execute function returns a Promise, so you'll either have to log the error by registering a callback via the catch function, or you need to add an await and make the whole function async. So either:

...
.execute({ destinationName: "sfapi" }) .then( ... ) .catch(error => { console.log(error.stack); });

or:

async function getWfRequestDetails() {
  try {
    var response = await WfRequest...
  } catch(e) {
    console.log(e.stack);
  } ...

By the way, I'm not sure what happens if you hand the whole error object to console.log. If you pass error.stack, it will definitely log the whole stacktrace.

0 Kudos

Hi dhem ,

Please find below the error trace:

Error: OData get by key request failed!
    at Object.errorWithCause (C:\MyWorkplace\Project\WorkerCouncilApp\MAIN\testextension\srv\node_modules\@sap\cloud-sdk-util\dist\error.js:14:20)
    at C:\MyWorkplace\Project\WorkerCouncilApp\MAIN\testextension\srv\node_modules\@sap\cloud-sdk-core\dist\request-builder\get-by-key-request-builder.js:107:90
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Caused by:
Error: get request to https://api12preview.sapsf.eu/odata/v2 failed! Unable to understand API request with character sequence: empWfRequestNav/* at character position number: 16 invalid characters: * . Refer to https://help.sap.com/viewer/d599f15995d348a1b45ba5603e2aba9b/PRODUCTION/en-US for correct API syntax and examples.
{"code":"ServerErrorException","message":{"lang":"en-US","value":"Unable to understand API request with character sequence: empWfRequestNav/* at character position number: 16 invalid characters: * . Refer to https://help.sap.com/viewer/d599f15995d348a1b45ba5603e2aba9b/PRODUCTION/en-US for correct API syntax and examples."}}
    at Object.errorWithCause (C:\MyWorkplace\Project\WorkerCouncilApp\MAIN\testextension\srv\node_modules\@sap\cloud-sdk-util\dist\error.js:14:20)
    at constructError (C:\MyWorkplace\Project\WorkerCouncilApp\MAIN\testextension\srv\node_modules\@sap\cloud-sdk-core\dist\request-builder\request\odata-request.js:208:29)
    at C:\MyWorkplace\Project\WorkerCouncilApp\MAIN\testextension\srv\node_modules\@sap\cloud-sdk-core\dist\request-builder\request\odata-request.js:197:73
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Caused by:
Error: Request failed with status code 500
    at createError (C:\MyWorkplace\Project\WorkerCouncilApp\MAIN\testextension\srv\node_modules\axios\lib\core\createError.js:16:15)
    at settle (C:\MyWorkplace\Project\WorkerCouncilApp\MAIN\testextension\srv\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (C:\MyWorkplace\Project\WorkerCouncilApp\MAIN\testextension\srv\node_modules\axios\lib\adapters\http.js:237:11)
    at IncomingMessage.emit (events.js:322:22)
    at endReadableNT (_stream_readable.js:1187:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

Thanks,

Harish

Accepted Solutions (1)

Accepted Solutions (1)

Hi harish_k824,

it seems that this service does not allow to select all fields, which is denoted by '*'. As other services do not allow this I will have to check back with the team whether and how we can solve this. In the meantime you can obtain the same results with the following:

WfRequest
  .requestBuilder()
  .getByKey(11111)
  .withCustomQueryParameters({
    $expand: WfRequest.WF_REQUEST_UI_NAV._fieldName,
    $select: WfRequest.WF_REQUEST_UI_NAV._fieldName
  })
  .execute({ destinationName: 'sfapi' });

Please also note, that for productive purposes selecting all properties of an entity is not recommended, consider doing the following. It will also spare you using the workaround:

WfRequest
  .requestBuilder()
  .getByKey(11111)
  .select(WfRequest.WF_REQUEST_UI_NAV.select(
    LinkedEntityName.SOME_PROPERTY
  ))
  .execute({ destinationName: 'sfapi' });

I hope that helps!

P. S. On the EDMX file I couldn't find any property that would correspond to WF_REQUEST_UI_NAV therefore it is possible that there are other issues as well.

0 Kudos

Thanks, marika.marszalkowski for the detailed response. I will update further after testing. To the second point, are you implying that there may be a different EDMX?

Thanks,

Harish

Answers (0)