How to get work item type attribute value?
Hi,
I am using the below function to retrieve work item type attribute value.
But it doen't return any value.
public static String getWorkitemTypeFieldValue(IWorkItem workItem,String fCustomStringAttributeID)
{
ITeamRepository repository = RepositoryManager.getInstance().getCurrentRepository();
IWorkItemClient workItemClient = (IWorkItemClient) repository.getClientLibrary(IWorkItemClient.class);
IAuditableCommon iac = workItemClient.getAuditableCommon();
IProgressMonitor monitor = new NullProgressMonitor();
IProjectArea projectArea = null;
try {
projectArea = getReportOneProjectArea();
} catch (TeamRepositoryException e2) {
e2.printStackTrace();
}
IAttribute customString = null;
try {
customString = workItemClient.findAttribute(projectArea, fCustomStringAttributeID, null);
} catch (TeamRepositoryException e) {
e.printStackTrace();
}
Object value = workItem.getValue(customString);
String sValue = "";
if(value!=null && value instanceof String) {
sValue = (String) value;
System.out.print("\tValue: " + sValue);
}
System.out.println();
return sValue;
}
Let me know is there any other way to get the value of work item type attribute.
I am using the below function to retrieve work item type attribute value.
But it doen't return any value.
public static String getWorkitemTypeFieldValue(IWorkItem workItem,String fCustomStringAttributeID)
{
ITeamRepository repository = RepositoryManager.getInstance().getCurrentRepository();
IWorkItemClient workItemClient = (IWorkItemClient) repository.getClientLibrary(IWorkItemClient.class);
IAuditableCommon iac = workItemClient.getAuditableCommon();
IProgressMonitor monitor = new NullProgressMonitor();
IProjectArea projectArea = null;
try {
projectArea = getReportOneProjectArea();
} catch (TeamRepositoryException e2) {
e2.printStackTrace();
}
IAttribute customString = null;
try {
customString = workItemClient.findAttribute(projectArea, fCustomStringAttributeID, null);
} catch (TeamRepositoryException e) {
e.printStackTrace();
}
Object value = workItem.getValue(customString);
String sValue = "";
if(value!=null && value instanceof String) {
sValue = (String) value;
System.out.print("\tValue: " + sValue);
}
System.out.println();
return sValue;
}
Let me know is there any other way to get the value of work item type attribute.
One answer
Your code looks OK to me.
You should check if the work item actually has the custom attribute and a value for it.
See:
https://jazz.net/forums/viewtopic.php?p=79043
https://jazz.net/forums/viewtopic.php?p=68390
You might have to run "synchronize attributes" to make sure all work items have the attribute. The other area to look at is the load profile for resolving/loading he work item. Not sure if you would get a value if you load with the SMALL_PROFILE.
You should check if the work item actually has the custom attribute and a value for it.
See:
https://jazz.net/forums/viewtopic.php?p=79043
https://jazz.net/forums/viewtopic.php?p=68390
You might have to run "synchronize attributes" to make sure all work items have the attribute. The other area to look at is the load profile for resolving/loading he work item. Not sure if you would get a value if you load with the SMALL_PROFILE.