cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SF API Select Using Navigation Property

huseyindereli
Active Contributor
0 Likes
19,757

Hi,

I'm using Cloud SDK for Javascript to fetch some data from SF OData API. It's working smoothly. ( Foundation platform, User Management API )

const getUserData = async function (userId) {
  const userApi = new UserApi();
  const resp = await userApi
    .requestBuilder()
    .getAll()
    .select(
      userApi.schema.USER_ID,
      userApi.schema.JOB_CODE,
      userApi.schema.DIVISION,
      userApi.schema.CUSTOM_01,
      userApi.schema.CUSTOM_02,
      userApi.schema.CUSTOM_03,
      userApi.schema.CUSTOM_04,
      userApi.schema.TOTAL_TEAM_SIZE,
      userApi.schema.DEFAULT_FULL_NAME,
      userApi.schema.LOCATION,
      userApi.schema.TITLE
    )
    .filter(userApi.schema.USER_ID.equals(userId))
    .execute({ destinationName: _dest });
  return resp;
};

But when I add a navigation property to select at the bottom of the TITLE like;

userApi.schema.HR

it's throwing an error (Cannot read properties of undefined (reading '_fieldName'))

When I add it like this;

userApi.schema.HR.select(userApi.schema.USER_ID)

It also throws an error ( Cannot read properties of undefined (reading 'select') )

I also couldn't find a specific schema for that Navigation Property (HR).

Any ideas how to get navigation properties ?

View Entire Topic
frank_essenberger1
Product and Topic Expert
Product and Topic Expert
0 Likes

Great that you use the SDK and it also runs smooth in most cases.

Before I investigate the problem using your service, could you try one quick thing. Can you get the api via the service object as describede here: https://sap.github.io/cloud-sdk/docs/js/features/odata/v2-client#select

const { businessPartnerApi, businessPartnerAddressApi } =
businessPartnerService();
businessPartnerApi
.requestBuilder()
.getAll()
.select(
businessPartnerApi.schema.FIRST_NAME,
businessPartnerApi.schema.TO_BUSINESS_PARTNER_ADDRESS.select(
businessPartnerAddressApi.schema.ADDRESS_ID,
businessPartnerAddressApi.schema.CITY_CODE
)
)
.execute(destination);


We do some init stuff within the service object. Let me know if it helps. If not I try to reproduce the error. Also if you face issues in the future feel free to open an issue on our OS repo: https://github.com/SAP/cloud-sdk-js/issues

We monitor all channels but the repo is our preferred one since it integrates best with our daily work flow.

Best

Frank

huseyindereli
Active Contributor
0 Likes

Thanks Frank for your quick response. Actually that link is a great source of information. I've been using it since the beginning but I couldn't find the type that HR navigation property is represented like businessPartnerAddressApi .

Also there is no UserService that I can use and I couldn't find HR definition in any of the classes.

Could this problem be specific to the SF APIs ? I can open an issue if you want to continue on that channel.

const { UserApi } = require("../generated/plt-user-mng/UserApi");

Dependencies;

"@sap-cloud-sdk/connectivity": "^2.10.0",

"@sap-cloud-sdk/core": "^1.54.2",

"@sap-cloud-sdk/odata-v2": "^2.10.0",

"@sap-cloud-sdk/generator": "^2.10.0",