It's all about the answers!

Ask a question

Can we find Work item using values of custom field?


A B (881811) | asked Sep 06 '11, 1:58 a.m.
Hi everyone,

We are using Java eclipse client and are trying to find a wrokitem using values of a particular custom filed(Which will always be unique for all WI's). Is it possible to do so?We are able to find a workitem using the RTC WI ID by using following:

findWorkItemById(ID, IWorkItem.SMALL_PROFILE, null);

It would be great help if some one can share any info,input or pointer.

-Regards,
Achal

One answer



permanent link
A B (881811) | answered Sep 06 '11, 7:36 a.m.
Hello everyone,

I created a code to fetch WI's ID using value of custom fields. This code works fine but for one issue. At first look it looks like a refresh issue but not sure what is happening. The scenarioo is:

Suppose for value 3900 of custom1 the code return 2 Wi's with ID 101 & 102. I change custom1 of 101 to "0" and run this code and as expected WI # 101 will disappear.

But if i again make cusotm1 of 101 to "3900" and execute the code it dont comes in result. Any ideas on to this?

-Regards,
Achal

P.S: I first tested this code with field priority. So some portion might look irrelevant.

/


public static void main(String[] args) {
TeamPlatform.startup();
try {
IProgressMonitor monitor = new SysoutProgressMonitor();
ITeamRepository repo = Snippet1.login(monitor);
System.out.println("Get auditable client");
auditableClient= (IAuditableClient)repo.getClientLibrary(IAuditableClient.class);
System.out.println("Going for list");
findWorkItems(repo,"AMT IDC Project Area",monitor);
} catch (TeamRepositoryException e) {
System.out.println("Unable to login: " + e.getMessage());
} finally {
TeamPlatform.shutdown();
}
}



public static List<IWorkItem> findWorkItems(ITeamRepository repo,String projectAreaName, IProgressMonitor monitor) throws TeamRepositoryException {

//--------------------------------------------------------------------------------------
System.out.println("Inside List");
IProcessClientService processClient= (IProcessClientService) repo.getClientLibrary(IProcessClientService.class);
URI uri= URI.create(projectAreaName.replaceAll(" ", "%20"));
IProjectArea projectArea= (IProjectArea) processClient.findProcessArea(uri, null, null);
if (projectArea == null) {
System.out.println("Project area not found.");
}
ITeamAreaHandle teamAreaHandle=(ITeamAreaHandle)projectArea.getTeamAreas().get(0);
ITeamArea teamArea = (ITeamArea) repo.itemManager().fetchCompleteItem(teamAreaHandle, IItemManager.DEFAULT, monitor);
IProjectAreaHandle projectAreaHandler = teamArea.getProjectArea();
//------------------------------------------------------------------------------------


//IWorkItem.PRIORITY_PROPERTY




IQueryableAttribute attribute= findAttribute(projectAreaHandler, "com.acn.adt.risk.attribute.custom1", monitor);
if (attribute == null){
System.out.println("Attribute is null");
return Collections.emptyList();
}

Identifier<IPriority> priorityIdentifier = null;
priorityIdentifier= Identifier.create(IPriority.class,"High");

//AttributeExpression dueExpression= new AttributeExpression(attribute, AttributeOperation.EQUALS,priorityIdentifier);
AttributeExpression dueExpression= new AttributeExpression(attribute, AttributeOperation.EQUALS,"3900");

IQueryableAttribute projectAreaAttribute= findAttribute(projectAreaHandler, IWorkItem.PROJECT_AREA_PROPERTY, monitor);
AttributeExpression projectAreaExpression= new AttributeExpression(projectAreaAttribute, AttributeOperation.EQUALS, projectAreaHandler);



Term term= new Term(Operator.OR);
term.add(projectAreaExpression);
term.add(dueExpression);

//------------------------------------------------------------------------


//IQueryCommon queryService= getService(IQueryCommon.class); //getQueryCommon();
IQueryCommon queryService= getQueryCommon(repo);
ItemProfile<IWorkItem> profile= getProfile(attribute).createExtension(IWorkItem.CREATOR_PROPERTY);
//Changed term over here
IQueryResult<IResolvedResult<IWorkItem>> result= queryService.getResolvedExpressionResults(projectAreaHandler,dueExpression, profile);
List<IWorkItem> matchingWorkItems= new ArrayList<IWorkItem>(result.getResultSize(monitor).getTotalAvailable());

while (result.hasNext(monitor)) {

matchingWorkItems.add(result.next(monitor).getItem());
}


for(int y=0; y < matchingWorkItems.size();y++)
{

System.out.println("This is Work Item ID " + matchingWorkItems.get(y).getId());
System.out.println("This is HTML Summary " + matchingWorkItems.get(y).getHTMLSummary());
}

return matchingWorkItems;
}


private static IQueryableAttribute findAttribute(IProjectAreaHandle projectArea, String attributeId, IProgressMonitor monitor) throws TeamRepositoryException {

IQueryableAttributeFactory factory= QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE);
return factory.findAttribute(projectArea, attributeId, auditableClient, monitor);
}

private static ItemProfile<IWorkItem> getProfile(IQueryableAttribute attribute) {
if (!attribute.isStateExtension())
return IWorkItem.SMALL_PROFILE.createExtension(attribute.getIdentifier());
return IWorkItem.SMALL_PROFILE.createExtension(IWorkItem.CUSTOM_ATTRIBUTES_PROPERTY, IExtensibleItem.TIMESTAMP_EXTENSIONS_QUERY_PROPERTY);
}

private static IQueryCommon getQueryCommon(ITeamRepository repo) {
return (IQueryCommon) repo.getClientLibrary(IQueryCommon.class);
}
}


}



Hi everyone,

We are using Java eclipse client and are trying to find a wrokitem using values of a particular custom filed(Which will always be unique for all WI's). Is it possible to do so?We are able to find a workitem using the RTC WI ID by using following:

findWorkItemById(ID, IWorkItem.SMALL_PROFILE, null);

It would be great help if some one can share any info,input or pointer.

-Regards,
Achal

		                                        

Your answer


Register or to post your answer.