It's all about the answers!

Ask a question

Querying using IWorkItem.OWNER_PROPERTY


Susan Hanson (1.6k2201194) | asked Oct 04 '12, 10:39 p.m.

I'm writing programmatic queries, and I need to query based on the work item owner.  I can get the IWorkItem.OWNER_PROPERTY:

IQueryableAttribute ownerAttribute = sourceRepo.findQueryableAttribute(IWorkItem.OWNER_PROPERTY);

AttributeExpression ownerExpress = new AttributeExpression(ownerAttribute, AttributeOperation.EQUALS, userID);

unresolvedItems.add(ownerExpress);

But I get a couple problems:

First is that I assume OWNER_PROPERTY is the userID and not the displayed userName, but I am not sure. Can someone confirm?

Second, i get an exception using this (I know it is this, as if I comment out the add(ownerExpress) line, so that it isn't querying with that clause, it doesnt' give the exception:

queryWorkItems: java.lang.IllegalArgumentException: Argument must be an instance of IAuditableHandle

java.lang.IllegalArgumentException: Argument must be an instance of IAuditableHandle

at com.ibm.team.workitem.common.internal.model.SetAttributeType.toString(SetAttributeType.java:69)

at com.ibm.team.workitem.common.internal.expression.AttributeValueFactory$ConstantValue.saveState(AttributeValueFactory.java:58)

at com.ibm.team.workitem.common.expression.AttributeExpression.saveValueProxy(AttributeExpression.java:165)

at com.ibm.team.workitem.common.expression.AttributeExpression.saveState(AttributeExpression.java:155)

at com.ibm.team.workitem.common.expression.Term.saveState(Term.java:189)

at com.ibm.team.workitem.common.internal.expression.XMLExpressionSerializer.serialize(XMLExpressionSerializer.java:132)

at com.ibm.team.workitem.common.internal.expression.XMLExpressionSerializer.serialize(XMLExpressionSerializer.java:57)

at com.ibm.team.workitem.common.internal.query.impl.QueryDescriptorCustomImpl.setExpression(QueryDescriptorCustomImpl.java:40)

at com.ibm.team.workitem.common.internal.query.QueryCommon.createQuery(QueryCommon.java:258)

at com.ibm.team.workitem.common.internal.query.QueryCommon.getResolvedExpressionResults(QueryCommon.java:123)

at archiveusertool.RTCRepoProjectArea.queryWorkItems(RTCRepoProjectArea.java:289)

One answer



permanent link
pugazhenthi samidurai (26423942) | answered Oct 05 '12, 1:44 a.m.
Hi Susan,

i hope it will help you to solve your issue.

Use the IContributor value instead of actual user id into the following expression.

AttributeExpression ownerExpress = new AttributeExpression(ownerAttribute, AttributeOperation.EQUALS, getOwner(userID));

This function will return the IContributor of the given User id :

private IContributor getOwner(String owner) throws TeamRepositoryException {

        IContributorManager icm = repository.contributorManager();
        return icm.fetchContributorByUserId(owner, monitor);
    }


Regards,

Pugazh S

Comments
Susan Hanson commented Oct 05 '12, 4:22 a.m.

perfect!  so ... perhaps you can help on the 2nd problem :-)   I am able to query but returns 2 work items, my test user has 1 unresolved and 1 resolved.  I have another clause in the query:

IQueryableAttribute stateAttribute = sourceRepo.findQueryableAttribute(IWorkItem.STATE_PROPERTY);

AttributeExpression workItemStatusExpression = new AttributeExpression(stateAttribute, AttributeOperation.STATE_GROUP_NOT_EQUALS, "closed");

unresolvedItems.add(workItemStatusExpression);

Perhaps this is another one of the "don't use a string" problems, because I checked the work item type that is "resolved" and the state group in the workflow has an id="closed" and name="Closed".

Susan

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.