Post

1 follower Follow
0
Avatar

How to apture projets and Task

I need to find a way to reference a project pull field from it then reference a tasks that is under the project and pull fields from those.  Can u give me an example of how to do this. Thanks

Import from old forum Answered

Please sign in to leave a comment.

1 comment

0
Avatar

The API Guide gives a couple of examples of using EntityQuery, just with different entities. The following is updated from the example for ContactPerson, which has a parent relationship with Customer.

The key is knowing what field defines the relationship; for tasks it's "ParentProject", which isn't listed in the documentation, but is listed as a standard field in the Settings Customization screens.

Of course, you don't need to have stored/hard-coded the project's uuid, just look up the Project by Name or other attribute using another EntityQuery. You can retrieve the matching EntityId(s) from QueryResult.Entities.

I haven't figured out a way to directly query the uuid (EntityId.Value) as an attribute of a query.

string projectId = "210a7ced-a440-45cd-9a30-1ff251b2b1fd";
EntityQuery query = new EntityQuery();
query.TypeName = "Task";
query.Fields = new string[] { "Name", "StartDate" };
Compare condition = new Compare();

condition.LeftExpression = new FieldExpression() { FieldName = "ParentProject" };
condition.Operator = Operator.Equal;

condition.RightExpression = new ConstantExpression() { Value = new EntityId {
TypeName = "Project", Value = projectId } };

query.Where = condition;
QueryResult result = client.Query(query);

Import from old forum 0 votes
Comment actions Permalink