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

SAP MDK - Entities, Navigations and Fields

vhsbc92
Explorer
0 Kudos
1,233

Hello community,

I would like to share an issue I encountered with entities and their navigation fields.

I have two entities:

  • cust_Turmas: Retrieves data from a class.
  • cust_Instrutores: Retrieves data from instructors.

There is also a navigation from cust_Turmas to cust_Instrutores, which is called cust_Inst1Nav.

Here is the filter used to retrieve the data using OData:

$select:externalCode,externalName,cust_Inst1Nav/cust_fname,cust_Inst1Nav/cust_lname
$expand:cust_Inst1Nav
$filter:externalCode eq 235

The URL parameter is:

<BASE_URL>/?$select=externalCode,externalName,cust_Inst1Nav/cust_fname,cust_Inst1Nav/cust_lname&$expand=cust_Inst1Nav&$filter=externalCode eq 235

The data retrieved by the query is:

{
  "@odata.context": "$metadata#cust_Turmas",
  "value": [
    {
      "externalCode": "235",
      "externalName": "Course name",
      "cust_Inst1Nav": {
        "externalCode": "123",
        "cust_fname": "Victor",
        "cust_lname": "Cardoso"
      }
    }
  ]
}

I thought I could simply call the navigation fields as I do with the main entity. For example:

  • {externalCode} = Retrieves 235
  • {cust_Inst1Nav/cust_fname} = should retrieve Victor, but instead, it either returns blank or doesn’t exist.

However, the navigation fields are not being retrieved.

Is there something I'm missing?

This is my page:

page with header to show only one recordpage with header to show only one record

 

Here is my Target object configuration detailed.

my Target configurationsmy Target configurations

 I can see the fields inside entity "cust_Turmas" its navigation "cust_Inst1Nav" when I want to set a field value in my objects.

image.png

 I've created a rule to get me some clues and put in a field:

export default function checkEmpty(context) {
    let binding = context.binding;

    if (binding.cust_Inst1Nav) {
        if (binding.cust_Inst1Nav.cust_lname) {
            return binding.cust_Inst1Nav.cust_lname;
        } else {
            return 'No Last Name Available';
        }
    } else {
        return 'cust_Inst1Nav not available';
    }
}

The result is: cust_Inst1Nav not available 

I appreciate any comments/suggestions.

Accepted Solutions (1)

Accepted Solutions (1)

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Are you using Offline OData?

If you are using offline the other thing to verify is that the $expand entity set is included in the defining requests in your Initialize action.  When I was running a test I didn't have my $expand entity set defined so naturally got no data back for the expand.

You can set your "SecureDatabaseEncryptionKey": false in your BrandedSettings.json and then pull the offline db files from your simulator/emulator and open in ilodata directly to confirm what data in in the offline store.

vhsbc92
Explorer
0 Kudos
Hi Bill, I'm using offline odata and it's not branded. I'm also checking everything you said and doing some analysis, I'll return asap.

Answers (2)

Answers (2)

bill_froelich
Product and Topic Expert
Product and Topic Expert

Your binding syntax is correct.  You can reference expanded fields using the navigation property slash property name references. Based on your data retrieved by the query it should work. 

If you haven't already, I would suggest turning on odata tracing and debug odata provider to confirm the query sent and data retrieved matches your expectations.  If you are using a branded client you can turn it on in the BrandedSettings.json or if using an app generated from a template under the user menu at runtime.

vhsbc92
Explorer
0 Kudos

@bill_froelich 

I’m speechless... incredible! Here's what I did to solve the issue:

I went to downloadOffline.action and InitializeOffline.action and added the expand I needed. After doing that, the previously blank fields were populated with the expected data.

image.png

Now I can see the data in the Object Header.

Thanks a lot! I'm learning a lot with you and all community's posts and members.

bill_froelich
Product and Topic Expert
Product and Topic Expert
Depending on the use case and data you can also included that entity set referred to by the navigation property rather than including it via the $expand. This will make all the data in that entity set available not just the expanded entries from the nav link.
vhsbc92
Explorer
0 Kudos
I got your point, but I'm not sure how and where I can do it. Would you mind to send a screenshot/file, please?
bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos
Add another Defining Request to the list that is the EntitySet that the cust_Inst1Nav points to and remove the $expand from the cust_Turmas query
vhsbc92
Explorer
0 Kudos
Got it, thanks!!