[Java]Change Programatically state of Work Item
Hello,
I need to change the state of a work item. I have done the following: public void changeWorkItemsState(IWorkItem workItem, ITeamRepository repository, IProjectArea projectArea)throws TeamRepositoryException { IAttribute internalState = findAttribute(repository, projectArea,"internalState"); Object value = workItem.getValue(internalState); Object newWorkItemState = "TEST.project.WorkFlow.state.s3"; workItem.setValue(internalState, newWorkItemState); } However,I get the following IPE exception: Exception in thread "main" com.ibm.team.repository.common.internal.ImmutablePropertyException at com.ibm.team.repository.common.internal.util.ItemUtil$ProtectAdapter.notifyChanged(ItemUtil.java:2051) at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:380) at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.setInternalState(WorkItemImpl.java:1045) at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.eSet(WorkItemImpl.java:2430) at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:1081) at com.ibm.team.workitem.common.internal.PropertyUtil.set(PropertyUtil.java:120) at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.setValue(WorkItemImpl.java:2949) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:600) Thanks in advance. |
Accepted answer
Ralph Schoon (63.4k●3●36●46)
| answered Feb 20 '13, 9:43 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER edited Feb 20 '13, 9:44 a.m.
Hi Fatla,
first you need a workingcopy and then you have to use another operation that sets the workflow action. You would use a workItemSave operation. Currently you could use setState, but that is deprecated. I have written something up around this here: http://rsjazz.wordpress.com/2012/11/26/manipulating-work-item-states/ Fatla 777 selected this answer as the correct answer
Comments
Fatla 777
commented Feb 20 '13, 10:41 a.m.
Thanks Ralph.
Dan Sevcenco
commented May 07 '13, 7:29 a.m.
Hello Ralph,
Please read the provided examples in https://rsjazz.wordpress.com/2012/11/26/manipulating-work-item-states/ and in https://rsjazz.wordpress.com/2012/11/27/resolve-parent-if-all-children-are-resolved-participant/ to understand that you have to provide a workflow action on save to change the sate of a work item.
Dan Sevcenco
commented May 07 '13, 8:07 a.m.
Hello Ralph,
Do the two examples work for you? Are you able to debug the code? Are you actually running into your code while debugging? Do you fetch the full state? Do you see if the save succeeds with its return value?
Dan Sevcenco
commented May 07 '13, 1:37 p.m.
OK, to answer all your questions:
Ralph Schoon
commented May 08 '13, 12:51 a.m.
| edited May 08 '13, 1:34 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You want to use saveWorkItem3 and use the technique described here: https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/ (see Communication Between Operations to Avoid Recursions) to prevent the recursion from happening. I think the same code is in the other downloads, but commented out.
Ralph Schoon
commented May 08 '13, 1:04 a.m.
| edited May 08 '13, 1:35 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
For completeness, another technique to prevent recursion when triggering on state changes is to compare the workflow state of the oldState and the workflow state of the newState and exit, if they are the same (no state change happened). But there are cases when this might not be appropriate and you want to use saveWorkItem3 and communication between the participants and advisors.
Dan Sevcenco
commented May 08 '13, 5:04 a.m.
Hello Ralph,
Dan, as long as I have no indicators what could be wrong, I am unable to help. It has worked for me in the past I can't tell what you are doing wrong.
Dan Sevcenco
commented May 08 '13, 6:38 a.m.
What kind of information could I get from RTC and give you that would help you understand what might be wrong?
I would expect to see at least an exception if something went wrong - transition not applicable, and the save status should show the save failed. Like in the code I publish:
IStatus saveStatus = fWorkItemServer.saveWorkItem3(parentworkingcopy, null, null, additionalParams); if (!saveStatus.isOK()) { // generate an error or do it in the calling method return false; }
Dan Sevcenco
commented May 08 '13, 9:18 a.m.
My code does the following:
showing 5 of 13
show 8 more comments
|
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.