It's all about the answers!

Ask a question

Re: Changing States of workitems programatically


VK L (8177156159) | asked May 24 '12, 3:59 a.m.
Hi All,
I am implementing a custom participant plugin. Based on certain conditions, i need to change the state of the workitem. I am using the setstate2() function, but not sure how to get the value of the Identifier <IState> for all the available states in the workflow.

Thanks.

10 answers



permanent link
sam detweiler (12.5k6195201) | answered May 30 '12, 9:36 p.m.
Thanks Sam. I figured it out and it works now.


Wonderful!

permanent link
VK L (8177156159) | answered May 30 '12, 9:27 p.m.
Thanks Sam. I figured it out and it works now.

permanent link
sam detweiler (12.5k6195201) | answered May 30 '12, 5:19 p.m.
you cannot save the read only copy of the workitem..
you must get & modify and save the workingcopy

// reference the right object type (cast)
IWorkItem workItem = (IWorkItem) auditable;
IWorkItem rr = (IWorkItem)workItem.getWorkingCopy();

permanent link
VK L (8177156159) | answered May 29 '12, 3:51 a.m.
Thanks Sam. This is the brief of my code:

IWorkItemServer service = getService(IWorkItemServer.class);
IWorkItem a = service.findWorkItemById(145, IWorkItem.FULL_PROFILE, monitor);
for (IAttributeHandle ia:a.getCustomAttributes())
{

IAttribute attribute= iac.resolveAuditable(ia,IAttribute.FULL_PROFILE, monitor);
a.setValue(attribute, finalexp);
IStatus st1 = service.saveWorkItem2(a, null, null);

I am getting assertion failed error at the setvalue method of the attribute. I read that we need to get a working copy of the item. My plugin is a server-side plugin and i couldnt find any options to setvalue or save work item using a working copy. How can this be done?

Thanks.

permanent link
sam detweiler (12.5k6195201) | answered May 28 '12, 7:51 a.m.
see my response in your other post.

net you can't use '.client' classes on the 'server'. '.client' is for Eclipse or standalone application side.

permanent link
VK L (8177156159) | answered May 28 '12, 4:34 a.m.
Hi Sam,
I get the below errors after including "com.ibm.team.workitem.client" dependency in manifest file:

2012-05-28 15:38:58,168 ERROR eam.repository.provision.internal.ProvisionService - CRJAZ0291I Failed to start the bundle "advisor.example 1.0.0.201205281530".
org.osgi.framework.BundleException: The bundle could not be resolved. Reason: Missing Constraint: Require-Bundle: com.ibm.team.workitem.client; bundle-version="3.0.2"
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1313)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolutionFailureException(AbstractBundle.java:1297)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:309)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:280)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:272)
at com.ibm.team.repository.provision.internal.ProvisionService.startFeatureBundles(ProvisionService.java:1341)
at com.ibm.team.repository.provision.internal.ProvisionService.installFromProfiles(ProvisionService.java:1049)
at com.ibm.team.repository.provision.internal.ProvisionService.installFromProfileNoWait(ProvisionService.java:1146)
at com.ibm.team.repository.provision.internal.ProvisionService.installFromProfile(ProvisionService.java:1084)
at com.ibm.team.repository.provision.internal.ProvisionService.installFromContextConfigurationUrl(ProvisionService.java:1163)
at com.ibm.team.repository.web.internal.Activator$1.run(Activator.java:125)
at java.lang.Thread.run(Thread.java:811)

* The component is available in the target platform path though (SDK).

Thanks.

permanent link
sam detweiler (12.5k6195201) | answered May 25 '12, 8:09 a.m.
you don't SAVE WITH the workingCopy class.. you GET a workingCopy (read/write) of the workitem (read only)..

then you save THAT with the saveWorkItem2() method

permanent link
VK L (8177156159) | answered May 25 '12, 6:46 a.m.
Hello.
My code looks like this:
IWorkItem sourceworkItem = (IWorkItem) auditable;


IProjectAreaHandle projectArea = sourceworkItem.getProjectArea();
IItemHandle item = sourceworkItem.getItemHandle();

IAuditableCommon iac = ((ISaveParameter) data).getSaveOperationParameter().getAuditableCommon();

Integer Id = sourceworkItem.getId();
String parentWItype = sourceworkItem.getWorkItemType();

IWorkItemServer workItemServer = this.getService(IWorkItemServer.class);
IStatus a1 = workItemServer.saveWorkItem(sourceworkItem, "Close");

I am getting a stale state error. I tried using the workingcopy, but unable to find the save method.

permanent link
Michele Pegoraro (1.8k14119103) | answered May 24 '12, 11:11 a.m.
Hi All,
I am implementing a custom participant plugin. Based on certain conditions, i need to change the state of the workitem. I am using the setstate2() function, but not sure how to get the value of the Identifier <IState> for all the available states in the workflow.

Thanks.


setState2 will not work. You have to use IWorkItemServer.saveWorkItem2 method.

Best regards,
Michele.

permanent link
sam detweiler (12.5k6195201) | answered May 24 '12, 8:14 a.m.
the IWorkflowInfo object has methods to get all the IDs and their text names.

the IWorkflowInfo can be located off the operation data

Object data= operation.getOperationData();
ISaveParameter p = (ISaveParameter)data;
IAuditableCommon iac = p.getSaveOperationParameter().getAuditableCommon();
WorkflowManager wfm = new WorkflowManager(iac);
// get the workflow this workitem is in, so we can get the labels of the states
IWorkItem workItem = (IWorkItem) auditable;
IWorkflowInfo x =wfm.getWorkflowInfo(workItem, monitor);

Your answer


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