oData inner filter in $expand - odata

Currently I am facing some issues while querying the oData services. I am very new to oData query syntax.
I am trying to query oData service using the following url
https://mysite/DataQueryGroups?$select=Id,Name&$filter=IsHidden eq false&IsShared ne false&$expand=DataQueries($select=Id,Name,IsPinned;)
which returns the desired results to me. Above query basically returns all DataQueryGroups where IsHidden=false and IsShared<>false, including the its child entity DataQueries.
Now I want to add filter to the DataQueries enity to display only those resulsts where IsPinned = true. So I have tried the following query
https://mysite/DataQueryGroups?$select=Id,Name&$filter=IsHidden eq false&IsShared ne false&$expand=DataQueries($select=Id,Name,IsPinned;$filter=IsPinned eq true;)
But this returns me the same results and it looks like its not considering the inner filter/last filter which I have specified on DataQueries entity.
I would like to know how to filter on parent and child entities and return the fields from both.
I am finding difficulties to under this syntax. Please let me know if anybody can help me on this issue.
I am using oData version 4.0
Thanking you in advance
Deepak

#Deepak
It seems that the latest Web API OData (v5.7) supports the nested filter in expand. See this issue: https://github.com/OData/WebApi/issues/127
I also wrote a sample project based on your model. It works on my side.
Would you please run it at your side and let me know any result. Thanks.

Related

OData Data read- latest entry on top

I am using OData API to read data in my Fiori Application. The issue is, in Odata API, the latest data entry is at the end rather it should be at the top. How do i do that ie put my latest data on top.
You can use the $orderby to decide what order the data is returned in. See the docs for more info. This URL is an example of ordering (using the OData TripPin example service) that sorts by the LastName property:
http://services.odata.org/V4/TripPinServiceRW/People?$orderby=LastName
We can use this same process to order by a DateTime value or an ID value to get your latest entries at the top. For example, here we order by the DateTimeOffset field StartsAt putting the latest entries first:
http://services.odata.org/V4/TripPinServiceRW/People('russellwhyte')/Trips?$orderby=StartsAt desc
1)
As mentioned before, you might have a look at server side sorting using “$orderby” as seen here.
2)
You might also want to check out the following tutorial on Sorting:
“
items="{
path : 'invoice>/Invoices',
sorter : {
path : 'ProductName'
}
}"
We add a declarative sorter to our binding syntax.
As usual, we transform the simple binding syntax to the object notation, specify the path to the data,
and now add an additional sorter property.
We specify the data path by which the invoice items should be sorted, the rest is done automatically.
By default, the sorting is ascending, but you could also add a property descending with the value true inside the sorter property to change the sorting order.”
Please see here and here
3)
This here might also be helpful:
“In this step, we will create a button at the top of the table which will change the sorting of the table.
When the current sorting state of the table is changed, the sorting state will be reflected in the URL.
This illustrates how to make the table sorting bookmarkable.”
Step 13: Make Table Sorting Bookmarkable
Sample: Navigation - Step 13 - Make Table Sorting Bookmarkable
4)
These links here also look interesting:
Sorting, Grouping and Filtering for Aggregation Binding
Sample: Sorting
Sample: With Sorting and Filtering Feature

How to get the last inserted row via Odata service

Update:
Using ODATA, How to get the last inserted row in /MySet where MySet.Name = "abc".
I do not want to continuously poll the odata service via model.read(). I know attachChange() or attachDataReceived()methods can be use to get notified automaically. But apart from notification, how to get the 'inserted row'. Also My doubt is how to satisfy the following three conditions here : $top=1, $orderby= Date desc and $filter=NAME eq 'ABC'
The only solution I can think of is to get notified by data inserted via attachDataReceived() and then make a model.read() call with the required filters and additional parameters. Although this would result in these additional 'read' calls.
Original Post Below:
Question: How to pass filters in element binding?
Post: I am using odata service for populating my views.
I want to pass certain filters like $filter=NAME eq 'Scott'
Since I want these parameters to be included only when with odata request for a specific ui-element, I want to include them in bindElement()
specifically something like this
var myFilter = new Array();
myFilter.push(new sap.ui.model.Filter("NAME", sap.ui.model.FilterOperator.EQ, 'Scott'));
var myStandardTile = this.byId("__tile3");
myStandardTile .bindElement("/MySet",{filters:myFilter});
But unfortunately this does not works. When I see the 'network' tab in developer console, Filters are not being added with my request.
You cannot. Neither filter nor sorter nor formatter are supported by element bindings. They are only supported by list and tree bindings.

Getting some data from Microsoft Graph unified OData endpoint

How to count number of items in EntitySet of MicrosoftGraph, for example 'users' or 'groups'? I tried:
https://graph.microsoft.com/v1.0/users?$count
Returns: lists all users
https://graph.microsoft.com/v1.0/users/$count
Returns:
{ "error": { "code": "Request_BadRequest", "message": "Unexpected segment Edm.Int32.", } }
Also in Annotations of target "microsoft.graph.directoryObject" which are those EntitySets based on I see that it is Selectable=false, Countable=false ...
Will $skip be ever available on 'users' or other toplevel EntitySet items ( https://graph.microsoft.com/v1.0/groups?$skip=5 ) ? It is available on other items ( https://graph.microsoft.com/v1.0/me/contacts?$skip=5 ). I know about $skipToken, but it is not the same.
Can I find somewhere in the $metadata if property is sortable? For example user.displayName is sortable, but user.mail or user.givenName are not. This would be handy in the $metadata. Is there plan to introduce this into $metadata?
OrderBy DESC in this formula https://graph.microsoft.com/v1.0/users?$orderBy=displayName%20desc is ignored, it shows items ordered ASC, am I doing something wrong?
Not much help I know, but if you do an API call that gets a Collection you can get a count using the second form you gave in the first question. Eg:
https://graph.microsoft.com/v1.0/users/<id>/events/$count
returns the count (6 in my case, and not in JSON - the returned data is actually "\x{ef}\x{bb}\x{bf}6" (in Perl formatting)). If we use the ? as the last separator (which is what http://graph.microsoft.io/en-us/docs/overview/query_parameters seems to indicate we should) with this URL:
https://graph.microsoft.com/v1.0/users/<id>/events?$count
I just get the list of events with no count as you do.
So that seems to indicate two things to me:
a) The $count doesn't appear to work as a query parameter, despite the documentation and the OData standards saying it should,
and
b) There seems to be a bug in the API for handling EntitySets which isn't there for Collections.
Sorry I can't be of more help, but its another data point at least (I just came unstuck with the same thing which is why I noticed this StackOverflow post!)
Ad 1. https://graph.microsoft.com/v1.0/users/$count is the correct OData syntax (http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part2-url-conventions/odata-v4.0-errata02-os-part2-url-conventions-complete.html#_Toc406398087), but as indicated in the metadata directoryObject collections are not currently countable. ODataV4 also allows $count in query parameters (http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part2-url-conventions/odata-v4.0-errata02-os-part2-url-conventions-complete.html#_Toc406398166), but then it should be specified with true or false value (e.g. https://graph.microsoft.com/v1.0/me/events?$count=true) and the response will include both the collection and its count in the #odata.count property. This is again not supported for directoryObject collections.
Ad 2. There is no plan right now to support $skip for directoryObject collections.
Ad 3. Yes, we plan to indicate which properties are sortable by in metadata using the SortRestrictions annotation defined in the OData capabilities vocabulary (http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/vocabularies/Org.OData.Capabilities.V1.xml)
Ad 4. Your request is correct, but we only support sorting users by displayName in the ascending order.

OData call with $filter and $expand simultaneously

I've been trying to call a entity, but i'm supposed to call the results from its associated entities. I tried to do it with the following URL:
/sap/opu/odata/XXXXXXXX/SERVICE_NAME/MatnrGetdetailCollection?$filter=IVendorId eq '1701' and ILanguage eq 'P' and IMaterial eq 'M-05'&$expand=MatnrClassGetdetail
I must use the filter because the called function has these mandatory parameters.
Am I making any mistake on the URL or the error isn't there?
In general $filter and $expand can be combined, we use it in our application. Therefore please see Layla's Comment. In addition, you should tell us what the actual error is.
If MatnrGetdetailCollection is indeed an entity set, then the corresponding entity must have a navigation property of the name MatnrClassGetdetail, otherwise $expand won't work.
There is some problem with the URL when you want to go for obligatory parameters. Please pass them as key values in segw and and go for the format I'm sending:
/sap/opu/odata/sap/SERVICE_NAME/EntitySet(keyfield='value',keyfield='value')/?$expand=navigationName

OData - filter by nested property

does anyone know how to express an OData $filter against a nested property?
for ex. I have the following Atom entry,
<entry>
...
<m:properties>
...
<d:RegardingObjectId m:type="Microsoft.Crm.Sdk.Data.Services.EntityReference">
<d:Id m:type="Edm.Guid">3f3712fd-fc49-e211-8eb8-000c296272c8</d:Id>
<d:LogicalName>new_sportsleague</d:LogicalName>
<d:Name>Boca</d:Name>
</d:RegardingObjectId>
I want to filter for those entries that have RegardingObjectId/LogicalName eq 'new_sportsleague'.
Tried with 'RegardingObjectId/LogicalName' and 'RegardingObjectId.LogicalName' with no luck.
'RegardingObjectId/LogicalName' would be the correct syntax.
For example:
http://services.odata.org/v3/OData/OData.svc/Suppliers
returns two results, whereas
http://services.odata.org/v3/OData/OData.svc/Suppliers?$filter=Address/Street eq 'NE 228th'
returns just one.
I don't see a place in the OData spec that explicitly states whether filtering using properties of a complex value is legal or not, but it seems that WCF Data Services supports it. It could be that other OData implementations don't.
Use following odata API example to access nested properties with filter data
http://192.168.50.152:50086/odata/StationOperationLogs/?$expand=ProductionStation,ProductionStation/ProductionUnit&$filter=ProductionStation/ProductionUnit/Id eq 2

Resources