0
votes

I am trying to query multiple projects in an Odata feed for our project server, but I have been unsuccessful so far. I am able to get individual project names and even exclude them, but when I try to query more than one project name I do not get the results I want. Perhaps my syntax is wrong. Any help with this would be greatly appreciated..

When I run this one it breaks and tells me that 'and' is an unknown operator:

http://$server/pwa/_api/ProjectData/Projects$filter=ProjectName -eq 'name1' and 'name2'

When I run this one it runs, but it still only looks at one value:

http://$server/pwa/_api/ProjectData/Projects$filter=ProjectName -eq 'name1' & 'name2'

According to this article this would be the right syntax the above statement using AND, but I am told that the syntax is wrong.

https://msdn.microsoft.com/en-us/library/ff478141.aspx

Also I even read this article to start with, which is a general overview of odata queries, but this is not really answering my question.

https://msdn.microsoft.com/en-us/library/office/jj163048.aspx

2

2 Answers

0
votes

I think there are a few changes you may need to make to get this to work the way you want:

  1. The property name on the PublishedProject entity, according to the $metadata, is 'Name' and not 'ProjectName'.
  2. Using conditional AND means that the project name would have to equal both 'name1' AND 'name2'. I think you really want conditional OR, so that the project name equals either 'name1' OR 'name2'
  3. You need two full expressions joined by conditional OR in order to filter for projects with 'name1' or 'name2'.
  4. '-eq' is the wrong syntax for an equality expression. Drop the hyphen and use just 'eq' (this is shown in the examples on the MSDN page you linked to.)

So your filter changes to:

?$filter=Name eq 'name1' or Name eq 'name2'

Or, the Url-encoded form:

?$filter=Name+eq+'name1'+or+Name+eq+'name2'

Optionally, you can use grouping in this query to make it a little easier to read:

?$filter=(Name eq 'name1') or (Name eq 'name2')

Disclaimer: I've only verified these filter examples work on a Project Online instance, not 2013.

0
votes

@RyanY I figured out just realized what I did wrong It was a problem with the logic I was using. Just as you said my syntax was wrong. I had checked earlier and no one answered my post. I was about to answer my own question just now and I saw your post..lol

To get my result I was looking for all I have to do is issue a REST query such as this:

http://$server/pwa/_api/ProjectData/Projects$filter=ProjectName eq 'name1' or ProjectName eq 'name2' or ProjectName eq 'name3'..ect

I like this idea btw I'll use that in the future its much more organized: ?$filter=(Name eq 'name1') or (Name eq 'name2')

Thanks for the feedback. Also my real name is Ryan too. What a coincidence :)