Post

1 follower Follow
0
Avatar

REST API Query Expression Not Accepting Operator

Hello,

I am trying to write a REST entity query that will return all of the Timesheet entries by a specific user where the project type is equal to a certain value, and the project name is NOT equal to several different project names. I am able to run a query that returns this for when the project name IS equal to one of the specified project names, bit I get a 500 error whenever I change this from "In" to "Not In".

Any idea why this might be happening, and could you please provide some guidance on doing this with the REST API?

It's a relatively long query, but here is what I have:

{

"TypeName": "Timesheet",

"Fields": ["Duration.value","CreatedBy.Name", "WorkItem.Name", "WorkItem.ProjectType.Name","ReportedDate"],

"Orders": [{"order":"Ascending","fieldName":"CreatedBy"}],

"Where": {

"_type": "And",

"conditions":[

{

"LeftExpression": {

"FieldName": "WorkItem"

},

"Operator": "In",

"RightExpression": {

"_type": "QueryExpression",

"Query": {

"TypeName": "WorkItem",

"_type": "EntityQuery",

"Where": {

"LeftExpression": {

"FieldName": "Project"

},

"Operator": "In",

"RightExpression": {

"_type": "QueryExpression",

"Query": {

"TypeName": "Project",

"_type": "EntityQuery",

"Where": {

"LeftExpression": {

"FieldName": "ProjectType"

},

"Operator": "Equal",

"RightExpression": {

"Value": "/ProjectType/Internal"

}

}

}

}

}

}

}

},

{

"LeftExpression": {

"FieldName": "CreatedBy"

},

"Operator": "In",

"RightExpression": {

"_type": "QueryExpression",

"Query": {

"TypeName": "User",

"_type": "EntityQuery",

"Where": {

"LeftExpression": {

"FieldName": "DisplayName"

},

"Operator": "Equal",

"RightExpression": {

"Value": "Alex Ayala"

}

}

}

}

},

{

"LeftExpression": {

"FieldName": "WorkItem"

},

"Operator": "Not In",

"RightExpression": {

"_type": "QueryExpression",

"Query": {

"TypeName": "Project",

"_type": "EntityQuery",

"Where": {

"_type": "Or",

"conditions": [

{

"LeftExpression": {

"FieldName": "Name"

},

"Operator": "Equal",

"RightExpression": {

"Value": "Admin"

}

},

{

"LeftExpression": {

"FieldName": "Name"

},

"Operator": "Equal",

"RightExpression": {

"Value": "PTO"

}

},

{

"LeftExpression": {

"FieldName": "Name"

},

"Operator": "Equal",

"RightExpression": {

"Value": "Holiday"

}

}

]

}

}

}

}]

}

}

 

 

 

 

 

Alex Ayala Answered

Please sign in to leave a comment.

1 comment

0
Avatar

Hi Alex,

A "Not in" operator is not supported. However, you could use a regular In operator and reverse the condition itself (use NotEqual operator).

Please note that you have 2 separate conditions for the Timesheet's (WorkItem.)Project. This is unnecessary. It complicates your query string and badly impacts performance. I recommend you use an And condition on the QueryExpression, and_ _include both conditions.

Also I suggest you use the IDs of projects and users, rather than names. This is better for performance and also consistent (as names can change)

Schematically it should be something like this:

where:

And (

  1. WorkItem in { And (1. Project != <Holiday Project Id>   2. Project != <_PTO Project Id> 3. _Project in {  Project type  = Internal  })}

  2. CreatedBy = <Alex Ayala's Id>

)

Hope this helps,

Ophir

Ophir Kenig 0 votes
Comment actions Permalink