How to add work item category programmatically in RTC project area ?
I am trying to add the work item category as a child for the root category "Unassigned" , it works fine when I add it manually but it does get added when I use the RTC API as shown below:
IAuditableClient auditableClient = (IAuditableClient) teamRepository
.getClientLibrary(IAuditableClient.class);
CategoriesManager catManager = CategoriesManager.createInstance(
auditableClient, projectArea, null);
CategoryTreeNode rootNode = catManager.getRoot();
CategoryTreeNode childCat = rootNode.createChild("childCategory");
catManager.save(monitor);
The code gets executed successfully but can not see the newly added child work item category in the project area.
Please correct me if I am missing anything.
Accepted answer
The code snippet is correct and it works perfectly fine( i tried it). Please recheck in eclipse client. Sometimes newly created items wont reflect in web UI. It should be there when checked from eclipse client.
Comments
For any mysterious reason if the above method is not working, you can create categories in following way also.
public ICategory createCategory( IProjectArea iProjectArea, String categoryName){
IWorkItemClient workItemClient = (IWorkItemClient) repository
.getClientLibrary(IWorkItemClient.class);
ICategory category = workItemClient.createCategory(iProjectArea, categoryName, monitor);
return workItemClient.saveCategory(category, monitor);
}
1 vote
For creation of sub categories
public ICategory createSubCategory(ICategoryHandle parentCategory, String categoryName){
IWorkItemClient workItemClient = (IWorkItemClient) repository
.getClientLibrary(IWorkItemClient.class);
ICategory category = workItemClient.createSubcategory(parentCategory,
categoryName, monitor);
return workItemClient.saveCategory(category, monitor);
}
1 vote