how to set WI status during creation in Plain Java Client?
Hello,
Given a String containing the name of the workitem state (like "New" or "Completed"), how can I create a workitem and set it's state to the one that corresponds to the string? I would like to be able to do that in one go if possible, as opposed to creating the workitem in state New and traversing the workflow to transfer the workitem to the desired state. |
Accepted answer
Ralph Schoon (63.7k●3●36●48)
| answered Dec 06 '13, 7:56 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi Piotr,
you can use the deprecated methiod workItem.setState2(value). The method directly sets the state and does not trigger any actions. That is the reason why it should not be used, because it would not respect required attributes etc. Another approach would be explained in https://rsjazz.wordpress.com/2012/11/26/manipulating-work-item-states/. Piotr Aniola selected this answer as the correct answer
Comments
Piotr Aniola
commented Dec 06 '13, 8:18 a.m.
Thanks you.
Piotr, as so often in the API, you would have to get the workflowInfo, then the available states and then find the right state with a name matching what you look for. Look into the code in my post above. for a workflow you can use
I came up with this protected void setStatus(IWorkItem workitem, String statusName) throws TeamRepositoryException { IWorkItemClient workItemClient = (IWorkItemClient)teamRepository .getClientLibrary(IWorkItemClient.class); IWorkflowInfo workflow = workItemClient.findWorkflowInfo(workitem, null); Identifier<istate>[] states = workflow.getAllStateIds(); for (Identifier<istate> state : states) { String name = workflow.getStateName(state); if (name.equalsIgnoreCase(statusName)) { workitem.setState2(state); return; } } throw new TeamRepositoryException("State " + statusName + " not found"); |
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.