Post

1 follower Follow
0
Avatar

REST API: Entity Query Where Condition with Specific Entity Field Value

Hello,

I am trying to do an entity query by allowing my where condition to contain a specific field value where the field happens to be an entity type. For example:

{

   "typeName":"Timesheet",

   "fields":["Duration.value","CreatedBy.Name", "WorkItem.Name"],

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

   "where":

   {

      "_type":"And",

      "conditions":[

         {

            "leftExpression":{"fieldName":"CreatedBy.Name"},

            "operator":"Equal",

            "rightExpression":{"value":"PERSON NAME HERE"}

         }

      ]

   }

}

So all I want to do is grab a couple of fields for Timesheet entries created by a specific person. The above query returns the error message: "Entity 'Timesheet' does not contain the field 'CreatedBy.Name'". I also tried DisplayName, with no success. Currently, the only way I can do this is by using the user id. The problem with this is that I want to use this similar approach for doing all kinds of different entity queries against different types of entities and entity field values, where it would be beneficial to just be able to look up the specific value we are querying by.

Please let me know if this makes sense and if anyone can assist here.

Alex Ayala Answered

Please sign in to leave a comment.

2 comments

0
Avatar

Hi Alex. You can't use a Compare condition directly on a referenced object field (x.y). You have to use a Compare _condition with the _In operator to achieve that. Here's a sample provided by my colleague which does something similar:

{

  "Fields": "ActualEffort,ExpectedROI,Score,Title,Work",

  "Orders": [

    {

      "FieldName": "Title",

      "Order": "Ascending"

    }

  ],

  "TypeName": "Issue",

  "Where": {

    "LeftExpression": {

      "FieldName": "CreatedBy"

    },

    "Operator": "In",

    "RightExpression": {

      "Query": {

        "TypeName": "User",

        "Where": {

          "LeftExpression": {

            "FieldName": "ExternalId"

          },

          "Operator": "Equal",

          "RightExpression": {

            "Value": "243edda2-622c-4f8a-a9e6-d677a1976607"

          }

        },

        "_type": "EntityQuery"

      },

      "_type": "QueryExpression"

    }

  },

  "Paging": {}

}

 

Hope this helps,

Ophir

Ophir Kenig 0 votes
Comment actions Permalink