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.
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
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/.
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/.
Comments
Thanks you.
How do I get the required state identifier based on the state name?
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
IWorkflowInfo.getAllStateIds() and then IWorkflowInfogetStateName(stateId)
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");}