How to query work item by status and change wi status programmatically?
Hi,
Thanks very much!
I have two requirement needed to be implement by Plain Java
1. Query the work item by status=resolved
2. Change the work item status to closed by action
Do you know how to do this?
I know the SDK2.0 wiki for create workitem, but do not know how to change status by action and query API.
Thanks very much!
2 answers
Jia,
you can use pre built queries and you can create queries. i believe Robin has some code to get you started here: http://ryehle.wordpress.com/2012/06/28/custom-build-result-pruner/
See Sam's answer https://jazz.net/forum/questions/84612/workitem-state-change-programatically?page=1&focusedAnswerId=84627#84627 for the state change. You can also search the SDK for examples. I found the code there.
you can use pre built queries and you can create queries. i believe Robin has some code to get you started here: http://ryehle.wordpress.com/2012/06/28/custom-build-result-pruner/
See Sam's answer https://jazz.net/forum/questions/84612/workitem-state-change-programatically?page=1&focusedAnswerId=84627#84627 for the state change. You can also search the SDK for examples. I found the code there.
I have used this kind of code to query:
IWorkItemClient workItemService = (IWorkItemClient) targetRepository
.getClientLibrary(IWorkItemClient.class);
IQueryClient queryClient = workItemService.getQueryClient();
IAuditableClient auditableClient = (IAuditableClient)targetRepository.getClientLibrary(IAuditableClient.class);
IQueryableAttribute attribute=QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(targetProjectArea, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, monitor);
Expression inProjectArea= new AttributeExpression(attribute,AttributeOperation.EQUALS, targetProjectArea);
IQueryResult<IResolvedResult<IWorkItem>> results=queryClient.getResolvedExpressionResults(targetProjectArea, inProjectArea,IWorkItem.SMALL_PROFILE);
results.setLimit(Integer.MAX_VALUE);
while (results.hasNext(monitor)) {
IResolvedResult<IWorkItem> resresult = (IResolvedResult<IWorkItem>) results.next(monitor);
IWorkItem item = resresult.getItem();
Not sure if there is a clause for querying a state group or state, I guess there is.
IWorkItemClient workItemService = (IWorkItemClient) targetRepository
.getClientLibrary(IWorkItemClient.class);
IQueryClient queryClient = workItemService.getQueryClient();
IAuditableClient auditableClient = (IAuditableClient)targetRepository.getClientLibrary(IAuditableClient.class);
IQueryableAttribute attribute=QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(targetProjectArea, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, monitor);
Expression inProjectArea= new AttributeExpression(attribute,AttributeOperation.EQUALS, targetProjectArea);
IQueryResult<IResolvedResult<IWorkItem>> results=queryClient.getResolvedExpressionResults(targetProjectArea, inProjectArea,IWorkItem.SMALL_PROFILE);
results.setLimit(Integer.MAX_VALUE);
while (results.hasNext(monitor)) {
IResolvedResult<IWorkItem> resresult = (IResolvedResult<IWorkItem>) results.next(monitor);
IWorkItem item = resresult.getItem();
Not sure if there is a clause for querying a state group or state, I guess there is.