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

How to move a Work Item to Close State programmatically

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

0 votes



8 answers

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

}

0 votes


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

0 votes


Permanent link
Thanks Marcel , it worked well..

0 votes


Permanent link

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?

0 votes


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

0 votes


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

0 votes


Permanent link
Hi
Yes, it should work that way.

Regards

Marcel
Jazz Work Item team

0 votes


Permanent link

Do we have any article on this?

Please share.

Thanks

0 votes

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,954

Question asked: Apr 28 '09, 9:19 a.m.

Question was seen: 9,418 times

Last updated: Dec 12 '12, 7:41 a.m.

Confirmation Cancel Confirm