It's all about the answers!

Ask a question

how to set WI status during creation in Plain Java Client?


Piotr Aniola (3.7k11738) | asked Dec 06 '13, 7:28 a.m.
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


permanent link
Ralph Schoon (63.1k33645) | 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.
How do I get the required state identifier based on the state name?


Ralph Schoon commented Dec 06 '13, 8:26 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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)



Piotr Aniola commented Dec 06 '13, 8:32 a.m. | edited Dec 06 '13, 8:39 a.m.

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


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.