It's all about the answers!

Ask a question

Is there no way to do a work item query by state?


Ernest Crvich (19211917) | asked Mar 26 '11, 1:02 a.m.
This fails to yield any results:

IQueryableAttribute recAttr = factory.findAttribute(
getProjectArea(), IWorkItem.STATE_PROPERTY,
auditableClient, null );
AttributeExpression recExpr = new AttributeExpression(
recAttr, AttributeOperation.EQUALS, "Resolved" );

And the IPredicate style fails just the same:

IPredicate predicate = WorkItemQueryModel.ROOT.internalState()._eq( "Resolved" );

So assuming I only have String objects representing the work item type ("defect") and work item state ("Resolved"), how do I do a query to retrieve only the work items with those two values?

The performance is terrible on pulling all work items regardless of state and doing the filtering on the back end.

4 answers



permanent link
Ernest Crvich (19211917) | answered Mar 30 '11, 7:56 p.m.
So it looks like WorkItemQueryModel.internalState() is actually comparing with an index number (in string form, e.g. "1", "2", "3") instead of the state name. One step forward...

But I can't find a way to convert a name ("Resolved") into this id/index...all the IWorkItem/IWorkflow) classes/interfaces I've dug into only provide methods to convert in the opposite direction.

Anyone know how to convert a state name into its index/id?

permanent link
Tim Hahn (511) | answered Apr 06 '11, 7:58 a.m.
JAZZ DEVELOPER
So it looks like WorkItemQueryModel.internalState() is actually comparing with an index number (in string form, e.g. "1", "2", "3") instead of the state name. One step forward...

But I can't find a way to convert a name ("Resolved") into this id/index...all the IWorkItem/IWorkflow) classes/interfaces I've dug into only provide methods to convert in the opposite direction.

Anyone know how to convert a state name into its index/id?


One thing you could do is run the methods you've found over the indexes you know about and build up the table in your own structure. Then you can use that to resolve back down to an integer (string) for use in the the query.

You could do the look-up over a loop until you get an error that the index isn't found. And do this look-up in some singleton so that you only have to build the table once and can re-use it on subsequent searches for work items.

Just a idea.

permanent link
Andre Weinand (4811) | answered Apr 06 '11, 1:23 p.m.
RTC always stores IDs and never display names (aka "labels") in the data base because the latter are subject to localization. So "Resolved" is a display name that will be different depending on your locale.

So queries must use the ID and not the label.
(For historical reasons some of the IDs still in use today have the form "1", "2", instead of the fully qualified identifiers like "com.ibm.team.apt.story.defined")

The WorkflowInfo class can be used to find display names for state and resolution IDs.
If you need a reverse mapping from display name to ID then this is an indication for a conceptual problem: you want to map a (potentially fragile) UI label to an ID.

This mapping is not only fragile because display names are translated, but it is also possible that a workflow will be customized by the user.

A robust way to query for states in face of translations and customizations is by using "state groups". All work flow states are required to fall into one of the three state groups "open", "inprogress", and "closed". These stategroups are available in queries through "StatusVariables" that you can easily integrate into your programmatically created queries:
new StatusVariable(IWorkflowInfo.OPEN_STATES)

(search for occurrences of StatusVariable in RTC source code for more examples)
At runtime a StatusVariable automatically expands into all states that fall into the specified state groups. This avoids that you will have to hardcode any states and it makes the query independent from localization and workflow customization.

--andre


Andre Weinand
Work Items

permanent link
Chen Feng (622) | answered Apr 21 '11, 7:16 a.m.
This fails to yield any results:

IQueryableAttribute recAttr = factory.findAttribute(
getProjectArea(), IWorkItem.STATE_PROPERTY,
auditableClient, null );
AttributeExpression recExpr = new AttributeExpression(
recAttr, AttributeOperation.EQUALS, "Resolved" );

And the IPredicate style fails just the same:

IPredicate predicate = WorkItemQueryModel.ROOT.internalState()._eq( "Resolved" );

So assuming I only have String objects representing the work item type ("defect") and work item state ("Resolved"), how do I do a query to retrieve only the work items with those two values?

The performance is terrible on pulling all work items regardless of state and doing the filtering on the back end.


I have the same problem, I cannot query workitems in some state. Can you tell me how did you solve your problem?

Your answer


Register or to post your answer.