Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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.

0 votes


Accepted answer

Permanent link
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

1 vote

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");

}

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,940
× 457
× 169

Question asked: Dec 06 '13, 7:28 a.m.

Question was seen: 4,468 times

Last updated: Dec 06 '13, 8:39 a.m.

Confirmation Cancel Confirm