IWorkItemCommon.findAttribute not working for built-in attributes
I'm writing a tool which should later import workitems from a text file. to get to know how to work with the jazz java api, I made a little test application
I can dynamilcally set the custom attributes of a custom work item type by passing the id and the value. but this procedure fails if i want to set a built-in attribute like the work item description.
the method findAttributes does return null for all built-in attributes, but works for all my custom attributes (I tried it with various fields with different data types).
Does findAttributes only work for custom attributes?
Below the code of my (simplified) application
EDIT: for some reason, " string, string " is shown as " string, string="" ", i have no idea why
String workItemSummary = "this is my summary";
String categories = "Projects/Hardware";
// get the category handle
List<String> categoryPath = Arrays.asList(CATEGORIES.split("/"));
ICategoryHandle categoryHandle = workItemClient.findCategoryByNamePath(projectArea, categoryPath, null);
// define key/value pairs for custom attributes
List<AbstractMap.SimpleEntry<String, string>> attributeValueList = new ArrayList<AbstractMap.SimpleEntry<String,String>>();
// built-in attribute, which cannot be found
attributeValueList.add(new SimpleEntry<String, string>("com.ibm.team.workitem.attribute.description", "this is the project info"));
// custom attribute which can be found and set
attributeValueList.add(new SimpleEntry<String, string>("com.mycompany.division.attr.managementaction", "this is the management action"));
// initialize the work item
WorkItemInitialization operation = new WorkItemInitialization(workItemSummary, categoryHandle, attributeValueList, workItemClient, projectArea, teamRepository);
// save the work item and return the id of the saved work item
IWorkItemHandle handle = operation.run(workItemType, null);
IWorkItem workItem = auditableClient.resolveAuditable(handle, IWorkItem.FULL_PROFILE, null);
return workItem.getId();
Work Item Initialization:
private static class WorkItemInitialization extends WorkItemOperation {
private String fSummary;
private ICategoryHandle fCategory;
private List<AbstractMap.SimpleEntry<String, string>> fAttributes;
private IProjectArea fProjectArea;
private IWorkItemClient fWorkItemClient;
private ITeamRepository fTeamRepository;
public WorkItemInitialization(String summary, ICategoryHandle category, List<AbstractMap.SimpleEntry<String, String>> attributes, IWorkItemClient workItemClient, IProjectArea projectArea, ITeamRepository teamRepo) {
fSummary = summary;
fCategory = category;
fAttributes = attributes;
fWorkItemClient = workItemClient;
fProjectArea = projectArea;
fTeamRepository = teamRepo;
}
@Override
protected void execute(WorkItemWorkingCopy workingCopy, IProgressMonitor monitor) throws TeamRepositoryException {
IWorkItem workItem = workingCopy.getWorkItem();
// set summary and category (working)
workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary));
workItem.setCategory(fCategory);
// try to set the attributes
if(fAttributes != null) {
for(AbstractMap.SimpleEntry<String, String> item : fAttributes) {
String attributeKey = item.getKey();
String attributeValue = item.getValue();
// get attribute definition (only working for the custom attribute)
IAttribute myAttribute = fWorkItemClient.findAttribute(fProjectArea, attributeKey, monitor);
if(myAttribute == null) {
// the built-in attributes are null here!!!!!
printMessage(attributeKey + " is null");
}
Object value = null;
String type = myAttribute.getAttributeType();
if(type != null) {
case "html":
value = XMLString.createFromPlainText(attributeValue);
break;
// other case's removed for better readablity
default:
value = attributeValue;
break;
}
if(value != null) {
workItem.setValue(myAttribute, value);
}
}
}
}
}
}
2 answers
This has always worked for me. See https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/ and use the interface IWorkItem to get the correct ID's e.g.
IWorkItem.DURATION_PROPERTY
Comments
I have found the solution. The string ID of the built-in attributes are different than those ID's which are shown in the jazz eclipse client.
To find out the ID do the following:
- Open the project area in the eclipse client
- Choose 'Process Configuration' tab
- Navigate to Project Configuration -> Configuration Data -> Work Items -> Types and Attributes
- click a built-in attribute and choose Edit
- instead of the whole ID path (like 'com.ibm.team.workitem.attribute.modified'), only use the last part ('modified').
---> for custom attributes, you have to use the whole path (like in the source code above)
I don't know if that is a bug or feature, but in my opinion, it is kind of confusing.