How to get Workitem attributes list
Accepted answer
Robert, I used this code and it has worked for me:
private boolean printAttributesOfType(IProjectArea projectArea,
String workItemTypeID, IProgressMonitor monitor)
throws TeamRepositoryException {
IWorkItemType workItemType = getWorkItemClient().findWorkItemType(
projectArea, workItemTypeID, monitor);
List<IAttributeHandle> builtInAttributeHandles = getWorkItemClient()
.findBuiltInAttributes(projectArea, monitor);
IFetchResult builtIn = getTeamRepository().itemManager()
.fetchCompleteItemsPermissionAware(builtInAttributeHandles,
IItemManager.REFRESH, monitor);
List<IAttributeHandle> custAttributeHandles = workItemType
.getCustomAttributes();
;
IFetchResult custom = getTeamRepository().itemManager()
.fetchCompleteItemsPermissionAware(custAttributeHandles,
IItemManager.REFRESH, monitor);
log("Attributes of Work Item type: " + workItemType.getDisplayName()
+ " ID: " + workItemType.getIdentifier());
log(" Built In Attributes");
printAttributeTypes(builtIn.getRetrievedItems(), monitor);
log(" Custom Attributes");
printAttributeTypes(custom.getRetrievedItems(), monitor);
return true;
}
private boolean printAttributesOfType(IProjectArea projectArea,
String workItemTypeID, IProgressMonitor monitor)
throws TeamRepositoryException {
IWorkItemType workItemType = getWorkItemClient().findWorkItemType(
projectArea, workItemTypeID, monitor);
List<IAttributeHandle> builtInAttributeHandles = getWorkItemClient()
.findBuiltInAttributes(projectArea, monitor);
IFetchResult builtIn = getTeamRepository().itemManager()
.fetchCompleteItemsPermissionAware(builtInAttributeHandles,
IItemManager.REFRESH, monitor);
List<IAttributeHandle> custAttributeHandles = workItemType
.getCustomAttributes();
;
IFetchResult custom = getTeamRepository().itemManager()
.fetchCompleteItemsPermissionAware(custAttributeHandles,
IItemManager.REFRESH, monitor);
log("Attributes of Work Item type: " + workItemType.getDisplayName()
+ " ID: " + workItemType.getIdentifier());
log(" Built In Attributes");
printAttributeTypes(builtIn.getRetrievedItems(), monitor);
log(" Custom Attributes");
printAttributeTypes(custom.getRetrievedItems(), monitor);
return true;
}
2 other answers
Firstly Thank you for such a quick response
Secondly: Is this code really correctly returns the names and values of attributes of a specific WorkItem?
for(int i = 0; i<workItemClient.findBuiltInAttributes(projectArea, monitor).size();i++){
//resolved.getItem() returns some workItem
com.ibm.team.workitem.common.model.IAttributeHandle handle = workItemClient
.findBuiltInAttributes(projectArea, monitor).get(i);
com.ibm.team.workitem.common.model.IAttribute attribute = (IAttribute) repository.itemManager().fetchCompleteItem(handle, IItemManager.DEFAULT, new NullProgressMonitor());
System.out.println(attribute.getDisplayName() +" " + resolved.getItem().getValue(attribute));
}
}
Secondly: Is this code really correctly returns the names and values of attributes of a specific WorkItem?
for(int i = 0; i<workItemClient.findBuiltInAttributes(projectArea, monitor).size();i++){
//resolved.getItem() returns some workItem
com.ibm.team.workitem.common.model.IAttributeHandle handle = workItemClient
.findBuiltInAttributes(projectArea, monitor).get(i);
com.ibm.team.workitem.common.model.IAttribute attribute = (IAttribute) repository.itemManager().fetchCompleteItem(handle, IItemManager.DEFAULT, new NullProgressMonitor());
System.out.println(attribute.getDisplayName() +" " + resolved.getItem().getValue(attribute));
}
I built it based on the code retrieves custom attributes:
for(int i = 0; i<resolved.getItem().getCustomAttributes().size();i++){
com.ibm.team.workitem.common.model.IAttributeHandle handle = resolved.getItem().getCustomAttributes().get(i);
com.ibm.team.workitem.common.model.IAttribute attribute = (IAttribute) repository.itemManager().fetchCompleteItem(handle, IItemManager.DEFAULT, new NullProgressMonitor());
System.out.println("The attribute id: " + attribute.getIdentifier());
System.out.println("The attribute name: " + attribute.getDisplayName());
System.out.println("The value of the custom attribute: " + resolved.getItem().getValue(attribute));
System.out.println("Type of the custom attribute: " + attribute.getAttributeType());
String typ = attribute.getAttributeType();
for(int i = 0; i<resolved.getItem().getCustomAttributes().size();i++){
com.ibm.team.workitem.common.model.IAttributeHandle handle = resolved.getItem().getCustomAttributes().get(i);
com.ibm.team.workitem.common.model.IAttribute attribute = (IAttribute) repository.itemManager().fetchCompleteItem(handle, IItemManager.DEFAULT, new NullProgressMonitor());
System.out.println("The attribute id: " + attribute.getIdentifier());
System.out.println("The attribute name: " + attribute.getDisplayName());
System.out.println("The value of the custom attribute: " + resolved.getItem().getValue(attribute));
System.out.println("Type of the custom attribute: " + attribute.getAttributeType());
String typ = attribute.getAttributeType();