Programmatically creating a work item in the java client api's.
I have searched through all the docs and have not been able to find a clear and concise example of how to connect to a project and team area and create a work item.
I have found some code that will create a work item but there is not any examples on how to find a team area by name.
This code is on the client side not server side.
Here is my code.
public static IWorkItemHandle createWorkItem(ITeamRepository repo, IProgressMonitor monitor) throws TeamRepositoryException { ITeamAreaHandle teamAreaHandle = ... //how do i find the team area by name??? ITeamArea teamArea = (ITeamArea) repo.itemManager().fetchCompleteItem(teamAreaHandle, IItemManager.DEFAULT, monitor); IProjectAreaHandle projectArea = teamArea.getProjectArea(); IWorkItemClient service = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class); IWorkItemType workItemType = service.findWorkItemType(projectArea, "defect", monitor); IWorkItemHandle handle = service.getWorkItemWorkingCopyManager().connectNew(workItemType, monitor); WorkItemWorkingCopy wc = service.getWorkItemWorkingCopyManager().getWorkingCopy(handle); IWorkItem workItem = wc.getWorkItem(); try { List<ICategory> findCategories= service.findCategories(projectArea, ICategory.FULL_PROFILE, monitor); ICategory category = findCategories.get(0); workItem.setCategory(category); workItem.setCreator(repo.loggedInContributor()); workItem.setOwner(repo.loggedInContributor()); workItem.setHTMLSummary(XMLString.createFromPlainText("Example work item")); IDetailedStatus s = wc.save(null); if(! s.isOK()) { throw new TeamRepositoryException("Error saving work item", s.getException()); } } finally { service.getWorkItemWorkingCopyManager().disconnect(workItem); } workItem = (IWorkItem) repo.itemManager().fetchCompleteItem(workItem, IItemManager.DEFAULT, monitor); monitor.subTask("Created a work item " + workItem.getId()); } |
2 answers
Ralph Schoon (63.7k●3●36●48)
| answered Mar 20 '15, 5:58 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
If you really want to use the WorkingCopyManager, this code has worked for me:
private void createWorkPackage(String sFId, String sSummary, String sDescript, String sTeamCat, String sPlanDate, String sDueDate, String sOwner) { try { IProgressMonitor monitor = new NullProgressMonitor(); IWorkItemClient workItemService = (IWorkItemClient) targetRepository .getClientLibrary(IWorkItemClient.class); IWorkItemHandle handle = workItemService.getWorkItemWorkingCopyManager() .connectNew(mappedInternalWorkItemType, monitor); WorkItemWorkingCopy wc = workItemService.getWorkItemWorkingCopyManager() .getWorkingCopy(handle); IWorkItem workItem = wc.getWorkItem(); try { List |
Ralph Schoon (63.7k●3●36●48)
| answered Mar 20 '15, 3:53 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER edited Mar 20 '15, 9:04 a.m.
This is explained here: https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation
If you need more code examples e.g. how to set attribute values, or find team areas by name look here: https://rsjazz.wordpress.com/2015/02/27/a-rtc-workitem-command-line-version-2-2/ and search the blog for keywords. Comments As a hint, you can use the WorkingCopyManager, but is is better to use the abstract class
WorkItemOperation instead. |
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.