Post

1 follower Follow
0
Avatar

Query ResourceLinks for All WorkItems of type Task

Greetings,

I'm working on a data extract from Clarizen for our task management system.  I need all projects with active tasks and their associated resources.  It looks like the most efficient (or at least fewest calls) way to get at all of the tasks, assignments and their associated projects is using the RegularResourceLink query, but I'm trying to limit the WorkItem Types to be just of the Type task.  Ideally I'd also like to limit it to tasks with a status of "Active" but it doesn't look like drilling into Entities is supported with Conditions and maybe that part of why I don't get any results?

 

Here is a trimmed down version what I came up with for the query object in my attempt to limit the workitem types returned by the query.  It doesn't return an error which makes me think I've got the right idea, but it also doesn't return any results so there is something off:

 VB:

Dim QueryConditions As New List(Of com.clarizen.api.Compare)

QueryConditions.Add(New com.clarizen.api.Compare With {

    .LeftExpression = New com.clarizen.api.FieldExpression With {.FieldName = "WorkItem"},

    .RightExpression = New com.clarizen.api.ConstantExpression With {.Value = New com.clarizen.api.EntityId With {.TypeName = "Task"}},

   .Operator = com.clarizen.api.Operator.Equal})

 

Dim query As com.clarizen.api.EntityQuery = New com.clarizen.api.EntityQuery()

With query

    .TypeName = "RegularResourceLink"

    .Fields = QueryFields.ToArray

    .Paging = New com.clarizen.api.Paging With {   .PageSize = 200, .PageSizeSpecified = True}

     .Where = New com.clarizen.api.And With {   .Conditions = QueryConditions.ToArray}

End With

 

So my questions are:  Am I on the right track and if so any suggestions?   Is there a better method of retrieving all projects with active tasks and the assignments?  I haven't really played with RetrieveMultipleMessage yet which seems like another plausible route?

Ryan McArthur Answered

Please sign in to leave a comment.

2 comments

0
Avatar

Hi Ryan.

The trick you need is using the In operator to specify a condition on the Workitem field of the RegularResourceLink.

Here is a sample that should be relevant for your needs. Also note that you can specify Project fields in the Fields collection, though the result will probably give you the project more than once.

EntityQuery eq = new EntityQuery

{

TypeName = "RegularResourceLink",

Where = new Compare

{

   LeftExpression = new FieldExpression { FieldName = "Workitem" },

   Operator = Operator.In,

   RightExpression = new QueryExpression

       {

   Query = new EntityQuery

              {

      TypeName = "Task",

      Where = new Compare

             {

         LeftExpression = new FieldExpression { FieldName = "State" },

         Operator = Operator.Equal,

         RightExpression = new ConstantExpression { Value = new EntityId { TypeName = "State", Value = "Active" } }

                    }

           }

     }

},

Fields = new string[] { "WorkItem.Name", "WorkItem.State", "WorkItem.Project.Name" }

};

 

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Perfect!  Thanks for your help.  In addition to the In operator I also didn't realize that the QueryExpression was available to express a query that the operator compares against.

I think you are correct that going deeper for project fields would cause projects to be returned multiple times.  Since this query already returns everything I need, my solution for that was to use the results build my own dictionaries that organized the data in a manner more relevant to our other apps, and using our internal identifiers.

Thanks again for the help!  :) 

Ryan McArthur 0 votes
Comment actions Permalink