RTC: how to retrieve work item type "name" via Java API
I mean: suppose you have a Project Change Request.
Its type is "projectchangerequest" (as it is retrieved from the workItem.getWorkItemType() method; this is the work item type "id"), but, on the form, it is displayed as "Project Change Request" (this is the work item type "name").
I need to retrieve this "name", but I cannot figure out how.
Any suggestions?
My RTC version is 4.0.6
Accepted answer
3 other answers
How do i get only workitem type id via java api?. Could you please let me know the complete syntax of this or Sample code?.
Thanks,
Rajiv
Comments
In order to retrieve the work item type id, you need a IWorkItem object, then you call the getWorkItemType method (look at my original post):
IWorkItem workItem = .....;
String workItemTypeID = workItem.getWorkItemType();
If you instead need the work item type name, I retrieve it with these code:
String workItemTypeName = "";
IWorkItemCommon workItemCommon = getService(IWorkItemCommon.class);
List<IWorkItemType> workItemTypes = workItemCommon.findWorkItemTypes(projectAreaHandle, null);
Hashtable<String, String> typesToNames = new Hashtable<String, String>();
for (IWorkItemType workItemType : workItemTypes) {
typesToNames.put(workItemType.getIdentifier(), workItemType.getDisplayName());
}
String workItemType = workItem.getWorkItemType();
if (typesToNames.containsKey(workItemType)) {
workItemTypeName = typesToNames.get(workItemType);
}
Be aware that in a P.A. you can have 2 different work item types with the same name, but different IDs.
I tried to get workitem id and set into one of attribute using below script but it is not working. Please correct me if it is wrong script.
FYI,
dojo.provide("workitemtype");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); // To access the work item attributes
dojo.require("com.ibm.team.workitem.api.common.Status"); // To create a status object to return
dojo.require("com.ibm.team.workitem.api.common.Severity"); // To create a severity for the status
(function() {
dojo.declare("workitemtype", null, {
getValue: function(attributeId, workItem, configuration) {
IWorkItem workItem = .....;
String workItemTypeID = workItem.getWorkItemType();
return workItemTypeID;
}
});
})();
Thanks,
Rajiv
Comments
Rajiv, it looks like you are writing a Javascript attribute customization.
Instead, I developed a Java extension (plugin).
So, my code won't work in your script.
I cannot help you, because I've never done such a thing with javascript.
Please file your own question next time, as this is already closed and for Java API. Thanks.
Please carefully read: https://jazz.net/wiki/bin/view/Main/AttributeCustomization especially https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript
Consider also to do the
From the first link you get that the JavaScript API syntax is:
workItem.getValue(WorkItemAttributes.TYPE);