It's all about the answers!

Ask a question

How to move a Work Item to Close State programmatically


r vijay (3676) | asked Apr 28 '09, 9:19 a.m.
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

8 answers



permanent link
John Doran (9182) | answered Apr 29 '09, 4:05 p.m.
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);

}

permanent link
Marcel Bihr, Jazz Work Item team (1.4k) | answered Apr 30 '09, 3:28 a.m.
JAZZ DEVELOPER
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

permanent link
r vijay (3676) | answered Apr 30 '09, 7:18 a.m.
Thanks Marcel , it worked well..

permanent link
Michele Pegoraro (1.8k1210398) | answered Aug 04 '09, 5:55 a.m.

If you have the action ID, you can then use
WorkItemServer#saveWorkItem(IWorkItem workItem, String workflowAction)


Hi, I have notice that saveWorkItem is depracated, and saveWorkItem2 have to be used instead. But this new method require a WorkItemReference object. What is it using for?

permanent link
Marcel Bihr, Jazz Work Item team (1.4k) | answered Aug 06 '09, 3:59 a.m.
JAZZ DEVELOPER
Hi
WorkItemReferences are a wrapper around repository links. If you do not modify links from or to the work item, you can simply pass in 'null'.

Regards

Marcel
Jazz Work Item team

permanent link
Michele Pegoraro (1.8k1210398) | answered Aug 06 '09, 5:06 a.m.
So, if I add or modify some links, can I retrieve WorkItemReferences using IWorkItemCommon.resolveWorkItemReferences from my WorkItem copy and then use it on saveWorkItem2 method togheter with WorkItem instance?

permanent link
Marcel Bihr, Jazz Work Item team (1.4k) | answered Aug 07 '09, 2:46 a.m.
JAZZ DEVELOPER
Hi
Yes, it should work that way.

Regards

Marcel
Jazz Work Item team

permanent link
Richie Rich (1232239) | answered Dec 12 '12, 7:41 a.m.

Do we have any article on this?

Please share.

Thanks

Your answer


Register or to post your answer.