How to move a Work Item to Close State programmatically
![](http://jazz.net/_images/myphoto/38be1381bbe88540469ba0492e81b91f.jpg)
8 answers
![](http://jazz.net/_images/myphoto/38be1381bbe88540469ba0492e81b91f.jpg)
Hi,
I have been trying to move a Work Item to Close State programmatically but couldnt succeed.
Can anyone help on this?
Thanks in Advance,
Vijay
Below is how I currently do it. I am positive there is a better way but I haven't figured it out yet. Hopefully someone from the Jazz team will respond.
public synchronized void changeWorkItemState(int workItemId,
String stateName, IProgressMonitor monitor)
throws TeamRepositoryException {
log.debug("changeWorkItemState");
IWorkItem workItem = findWorkItemById(workItemId, monitor);
IWorkflowInfo workflowInfo = workItemServer.findWorkflowInfo(workItem,
monitor);
Identifier<IState>[] states = workflowInfo.getAllStateIds();
// get working copy
IWorkItem workingCopy = (IWorkItem) workItem.getWorkingCopy();
//there has to be a better way
for (int i = 0; i < states.length; i++) {
if (stateName.equals(workflowInfo.getStateName(states[i]))) {
workingCopy.setState2(states[i]);
break;
}
}
workItemServer.saveWorkItem2(workingCopy, null, null);
}
![](http://jazz.net/_images/myphoto/38be1381bbe88540469ba0492e81b91f.jpg)
Hi
The correct way to do a workflow transition is to use an action. The IWorkflowInfo has a method 'getResolveActionId' that return the id of the action that is configured in the process spec to be the 'Resolve Action'.
If you however want the work item to be in a specific well-known state (e.g. state 'Closed'), you have to find a valid action leading from the current state of the work item to the desired one.
If you have the action ID, you can then use
WorkItemServer#saveWorkItem(IWorkItem workItem, String workflowAction)
Regards
Marcel
Jazz Work Item team
The correct way to do a workflow transition is to use an action. The IWorkflowInfo has a method 'getResolveActionId' that return the id of the action that is configured in the process spec to be the 'Resolve Action'.
If you however want the work item to be in a specific well-known state (e.g. state 'Closed'), you have to find a valid action leading from the current state of the work item to the desired one.
If you have the action ID, you can then use
WorkItemServer#saveWorkItem(IWorkItem workItem, String workflowAction)
Regards
Marcel
Jazz Work Item team