Fetching the tasks under particular Story

66 Views Asked by At

Am trying to find the list of tasks under a specific story by passing the story Formatted ID, but am not getting the tasks listed under that story.

        QueryRequest taskRequest = new QueryRequest("task");
        taskRequest.setFetch(new Fetch("FormattedID","Name","PlanEstimate"));
        taskRequest.setQueryFilter(new     QueryFilter("FormattedID","=","TJ87631"));
        QueryResponse taskRes = restApi.query(taskRequest);
        int count = taskRes.getTotalResultCount();
        System.out.println("task count is " + count);

I tried passing projectRef and WorkspaceRef to the QueryFiletr even though i have passed Story FormattedID which actually suffice.

Please let me know, what's wrong in the code...

3

There are 3 best solutions below

0
On

Just guessing; maybe the query is looking for "programming language" like comparison instructions, like:

taskRequest.setQueryFilter(new QueryFilter("FormattedID","==","TJ87631"));

Meaning: try using "==" instead of "=" !

0
On

What you have should work, assuming TJ87631 is the correct formatted id of the parent story. It doesn't look like you have specified any project scoping. Are those tasks and that story in your default project? If not you'll need to set the project on your query.

The other approach is to just load the tasks collection on that story, if you already have that story in memory:

QueryRequest tasksQuery = new QueryRequest(story.get("Tasks"));
0
On

I've been working on the c# version but I would assume it's about the same.

Is TJ87631 the reference for the user story ?

If so try:

taskRequest.setQueryFilter(new QueryFilter("WorkProduct.FormattedID","=","TJ87631"));

When I was working with it, you need to reference the parent.formattedid.

However if you have access to the object id (work product.oid) I've found it more reliable to use for filtering.