cancel
Showing results for 
Search instead for 
Did you mean: 

How to use $select to get value from nested object like UpdateInformation using OData?

Jeff
Archer Employee
Archer Employee

When using $select to select specific properties from the topmost JSON object, it works great.  But when trying to select a property from a nested object, it fails.  If I reference the property in a nested object with $filter, this works great. 

 

For example, the following works getting topmost properties.  Notice UpdateInformation is a nested object, but I only want to get the CreateLogin value.

/api/core/system/fielddefinition/application/69?$select=Id,Name,Alias,UpdateInformation

{
"Id": 107,
"Name": "Facility ID",
"Alias": "Facility_ID",
"UpdateInformation": {
"CreateDate": "2006-01-20T03:00:47.373",
"UpdateDate": "2018-06-27T18:58:57.41",
"CreateLogin": 2,
"UpdateLogin": 2
}
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

I tried this format, but it fails:

/api/core/system/fielddefinition/application/69?$select=Id,Name,Alias,UpdateInformation/CreateLogin
[
{
"Links": [],
"RequestedObject": {},
"IsSuccessful": false,
"ValidationMessages": [
{
"Reason": "WebApi:WebApiOdataValidationExceptionReason",
"Severity": 3,
"MessageKey": "WebApi:WebApiOdataValidationException",
"Description": "Inner or start path segments must be navigation properties in $select.",
"Location": -1,
"ErroredValue": null,
"Validator": "ArcherTech.Web.Api.OData.Validators.ODataQueryOptionValidator, ArcherTech.Web.Api.OData, Version=6.5.300.1038, Culture=neutral, PublicKeyToken=null",
"XmlData": null,
"ResourcedMessage": "OData query validation failed"
}
]
}
]‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

Using the format above for $filter works:

/api/core/system/fielddefinition/application/69?$select=Id,Name,Alias&$filter=UpdateInformation/CreateLogin ne 2

 

I tried using $expand, but it looks like this is not enabled or allowed.  The documentation doesn't show the $expand keyword, but it was worth a shot.

/api/core/system/fielddefinition/application/69?$select=Id,Name,Alias&$expand=UpdateInformation($select=CreateLogin)

[
{
"Links": [],
"RequestedObject": {},
"IsSuccessful": false,
"ValidationMessages": [
{
"Reason": "WebApi:WebApiOdataValidationExceptionReason",
"Severity": 3,
"MessageKey": "WebApi:WebApiOdataValidationException",
"Description": "Query option 'Expand' is not allowed. To allow it, set the 'AllowedQueryOptions' property on EnableQueryAttribute or QueryValidationSettings.",
"Location": -1,
"ErroredValue": null,
"Validator": "ArcherTech.Web.Api.OData.Validators.ODataQueryOptionValidator, ArcherTech.Web.Api.OData, Version=6.5.300.1038, Culture=neutral, PublicKeyToken=null",
"XmlData": null,
"ResourcedMessage": "OData query validation failed"
}
]
}
]‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
6 REPLIES 6

Ilya_Khen
Champion III

Jeff, I seriously tried my best  But seems like without enabling $expand (

EnableQueryAttribute or QueryValidationSettings

), this would not be possible

I got the same as well. I tried a combination of both $select & $expand. It throws the below error.

"Query option 'Expand' is not allowed. To allow it, set the 'AllowedQueryOptions' property on EnableQueryAttribute or QueryValidationSettings."

 

/api/core/system/fielddefinition/26614?$select=Id,Name,Alias&$expand=UpdateInformation‍‍‍‍

Edit: $filter also not working for me.

$filter worked fine for me, but you cannot reach nested structure still via filter alone

Yeah. Concur with you on the hierarchy part.

 

Filter also throws the same error for me. 

 

Did you try other options? Like $top,$skip,$orderby,$inlinecount,etc.,.

 

If they don't work, I guess there is something to be checked at the application code level.  

Nope, but it could be also related either to limitation of properties, e.g. Expand needs to be enabled first and allowed before using. Plus, some of the commands were introduced in further versions of ODATA, and this could be v1

Yeah. Maybe v1.