Create new work item server side (Java)
![]()
I need to create a new work item with my java extension on the server side. I found a few examples with the client api but I can't seem to find out how it works with the server side java api.
I found a method createWorkItem but I need to give it a work item type. From the work item type I have the id but not the object So I don't know how to get the work item type object and if the method I found is indeed the correct one to use Can anyone help? |
Accepted answer
![]() Use the IFindWorkItemType method of your IWorkItemServer. Example:
IWorkItemType myType = wiService.findWorkItemType(myProjectArea, "myCustomTypeID", monitor);
Here's the JavaDoc for the findWorkItemType method:
IWorkItemType com.ibm.team.workitem.common.IWorkItemCommon.findWorkItemType(IProjectAreaHandle projectArea, String identifier, IProgressMonitor monitor) throws TeamRepositoryException
Returns the work item type with the given identifier in the given project area or
Ilona Krammer selected this answer as the correct answer
|
One other answer
![]()
Hi,
to create a work item you need to use the IWorkItemServer.createWorkItem2 method. Once created you can use the different setters to set the value you want. Eventually you need to save it using IWorkItemServer.saveWorkItem2 method. An example where I also set a child link: IWorkItemType wiType = wiService.findWorkItemType(myProjectArea, "task", monitor); IWorkItem task = wiService.createWorkItem2(wiType); task.setHTMLSummary(XMLString.createFromPlainText("Child Task of " + wi.getHTMLSummary().getPlainText())); IAttribute plannedForAttribute = wiService.findAttribute(wi.getProjectArea(), WorkItemAttributes.PLANNED_FOR, null); task.setValue(plannedForAttribute, wi.getValue(plannedForAttribute)); IWorkItemReferences references = wiService.resolveWorkItemReferences(task, null); IReference workPackageReference = IReferenceFactory.INSTANCE.createReferenceToItem(wi); references.add(WorkItemEndPoints.PARENT_WORK_ITEM, workPackageReference); IStatus status = wiService.saveWorkItem2(task, references, null); if(status.isOK()){ return true; }else{ return false; } Best regards, Michele. Comments Even though that's actually another question, but: how do you get the planned for attribute? I try to use WorkItemAttributes but there is no constant PLANNED_FOR that I can use..
Illona, the constant for "Planed For" is
Thank you sooo much guys!
![]() FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Don't know where this get lost:
|