Skip to content
This repository was archived by the owner on Jun 18, 2024. It is now read-only.

Filter parameters not applied properly in ListClient queries #61

Closed
TBag opened this issue Dec 18, 2014 · 4 comments
Closed

Filter parameters not applied properly in ListClient queries #61

TBag opened this issue Dec 18, 2014 · 4 comments
Assignees

Comments

@TBag
Copy link

TBag commented Dec 18, 2014

The SDK generates incorrect URLs when filters are applied to a SharePoint list query. The following code demonstrates this issue.

public int getInspectionPhotoId(int incidentId,int roomId, int inspectionId,int top) throws ExecutionException, InterruptedException {
        String[] select = {"Id"};
        Query query = new Query().select(select)
                .parameter("sl_inspectionIDId",String.valueOf(inspectionId))
                .parameter("sl_incidentIDId",String.valueOf(incidentId))
                .parameter("sl_roomIDId",String.valueOf(roomId))
                .top(top)
                .orderBy("Modified", QueryOrder.Descending);
        List<SPListItem> items = mClient.getListItems(Constants.LIST_NAME_ROOMINSPECTIONPHOTOS, query).get();
        if(items != null && items.size() > 0){
            return items.get(0).getId();
        }

        return 0;
    }

The SDK generates this URL:

https://teeudev3.sharepoint.com/sites/SuiteLevelAppDemo/_api/web/lists/GetByTitle('Room%20Inspection%20Photos')/Items?$filter=&$top=1&$orderby=Modified+desc&sl_InspectionIDId=40&sl_incidentIDId=49&sl_roomIDId=1&$select=Id 

The problem is the filter parameters do not follow the $filter= parameter.

The correct URL should look like this:

https://teeudev3.sharepoint.com/sites/SuiteLevelAppDemo/_api/web/lists/GetByTitle('Room%20Inspection%20Photos')/Items?$filter= sl_inspectionIDId%20eq%2040%20and%20sl_incidentIDId%20eq%2049%20and%20sl_roomIDId%20eq%201&$top=1&$orderby=Modified+desc&$select=Id
@marcote
Copy link
Contributor

marcote commented Dec 18, 2014

Hi @TBag . I'm currently OOF, but I'll be back next Monday.
Regards

@marcote marcote self-assigned this Dec 18, 2014
@TBag
Copy link
Author

TBag commented Dec 18, 2014

OK, thanks for the heads up.

@marcote
Copy link
Contributor

marcote commented Dec 29, 2014

@TBag sorry about the delay, had to recover from a small surgery first.

I tried to reproduce the defect and if you want to use filter, you shouldn't use parameter. Use instead:

Query query = new Query().select(select)
.field("sl_inspectionIDId").eq(inspectionId)
.field("sl_incidentIDId").eq(incidentId)
.field("sl_roomIDId").eq(roomId)
.top(top)
.orderBy("Modified", QueryOrder.Descending);

and the result is the following one:

https://somehost.sharepoint.com/test/_api/web/lists/GetByTitle('somelistname')/Items?$filter=sl_inspectionIDId+eq+(10)+sl_incidentIDId+eq+(20)+sl_roomIDId+eq+(30)&$top=5&$orderby=Modified+desc&$select=Id

Let me know if this works for you.
Thanks

@marcote marcote closed this as completed Dec 30, 2014
@TBag
Copy link
Author

TBag commented Jan 5, 2015

Hi Marcos,

That code you suggested works well. Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants