IWorkItemCommon.findAttribute not working for built-in attributes
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();
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
IWorkItem.DURATION_PROPERTY
Comments
Hi Ralph
The values (attributeValueList) shall be read dynamically in the future, so it would be easier if I could use the ID (in string format) instead of mapping the ID to the different interface properties (e.g. IWorkItem.DURATION_PROPERTY)
I believe I have successfully done that. I have no time to test it for you. I would try to check the value of the IWorkItem attribute ID, you can pass that. To evaluate your code works at all, I would start with the IWorkItem interface. Make sure it works and then stat looking at ID Strings.
The code works for me except for the built-in attributes when i pass the ID. So in the example above, the work item is being created with summary, category and managementaction set.
If i set the description by using the interface, it works as well
workItem.setValue(myAttribute2, "my description");
Comments
From my personal perspective, I would consider this a defect - the ID's presented in the UI should be the ones that work. I remember I had similar issues in the past, but I am unsure if I could solve this to use the full ID's.
the related defect is resolved as 'wont fix', so my answer is still valid
@lukas, I had forgotten but I filed a similar defect aeons ago. It is still alive, I think. You can not use the external ids from the eclipse client. You have to use the internal ones from the web UI. Note, the WCL has a command to print the real ids for the built in and custom attributes of a type.