It's all about the answers!

Ask a question

Create new work item server side (Java)


0
1
Ilona Krammer (159449) | asked Oct 12 '16, 5:41 a.m.
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


permanent link
Miguel Tomico (5001323) | answered Oct 12 '16, 6:06 a.m.

Use the IFindWorkItemType method of your IWorkItemServer. Example:

IWorkItemType myType = wiService.findWorkItemType(myProjectArea, "myCustomTypeID", monitor);
IWorkItem myNewWorkItem = wiService.createWorkItem2(myType);

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 null if no type with this identifier is configured in the process configuration.

Parameters:
projectArea the project area
identifier the type identifier
monitor a progress monitor or null
Returns:
the work item type or null
Throws:
TeamRepositoryException - if anything goes wrong

Ilona Krammer selected this answer as the correct answer

One other answer



permanent link
Michele Pegoraro (1.8k14118103) | answered Oct 12 '16, 6:09 a.m.
edited Oct 12 '16, 11:02 a.m.
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
Ilona Krammer commented Oct 13 '16, 2:28 a.m.

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..

and if I use the id for the attribute as stated in the properties (com.ibm.team.workitem.attribute.target) I always get back null

What can I do?


Ralph Schoon commented Oct 13 '16, 3:19 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Illona, the constant for "Planed For" is

com.ibm.team.workitem.common.model.IWorkItem.TARGET_PROPERTY

I shared some hints here: https://rsjazz.wordpress.com/2012/10/05/handling-iterations-automation-for-the-planned-for-attribute/


Ilona Krammer commented Oct 13 '16, 7:08 a.m.

Thank you sooo much guys!


Ralph Schoon commented Oct 13 '16, 8:13 a.m. | edited Oct 13 '16, 8:15 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Don't know where this get lost:

Ilona, the best way to get the attribute ID for built in attributes in RTC today is the Web Admin UI. See the column "ID" the value here for Planned For is "target".

The Eclipse client provides an odd external ID that you can't use. I reported this, but it was never addressed.





Your answer


Register or to post 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.