How to Set Attribute of a Work Item in an Asynchrounous Task?
Hi,
I'm implementing an asynchronous task and have gotten some work items as I expected. My question is, how to set a specific attribute with my own value for a work item? Is it possible to do that in an asynchronous task? I've tried to get a workingCopy before I call the setValue method. However, it returns an 'assertion exception' and I have no idea how to deal with it. Please help on this issue, thanks! |
3 answers
Hello Kenery,
IWorkItem findWorkItem = workItemClient.findWorkItemById(currentWorkItemID, IWorkItem.FULL_PROFILE, monitor); Comments
Kenery Wang
commented May 05 '16, 3:47 a.m.
Hi Hakki,
Hakki Bozkurt
commented May 05 '16, 3:58 a.m.
Hello Kenery, Yes I have, what are you trying to do? Operation Participant (server side plugin)?
Please check this https://jazz.net/forum/questions/205679/creating-an-advisor-plugin-for-rtc-version-50/205718
Kenery Wang
commented May 05 '16, 4:06 a.m.
I'm implementing an asynchronous task: https://jazz.net/wiki/bin/view/Main/AsynchronousTasks
I have experience in working with Operation Participant. Now I'm facing the problem with asynchronous task which the 'setValue' method works well in 'Operation Participant' but fails in 'Asynchronous Task'.
|
I'm assuming that saying "asynchronous task" you mean an event handler (as advisor and follow-up are synchronous).
On server side you need to use this, where workItemService is an instance of IWorkItemServer: IWorkItem freshCopy = (IWorkItem)workItemService.findWorkItemById(wi.getId(), IWorkItem.FULL_PROFILE, null).getWorkingCopy(); freshCopy.setValue(automationAttribute, Boolean.valueOf(false)); workItemService.saveWorkItem2(freshCopy, null, null); Comments Hi Michele,
The "asynchronous task" can be referred from https://jazz.net/wiki/bin/view/Main/AsynchronousTasks
I already got my work item and got a workingCopy of it, the main problem is I cannot set attribute with a specific value to the work item.
Below is my code snippet
IWorkItem workingCopy = (IWorkItem) fworkItemServer.getAuditableCommon().resolveAuditable(workItem, IWorkItem.FULL_PROFILE, null);
workingCopy.setValue(attribute_delayDays, value_delayDaysDiff);
Hakki Bozkurt
commented May 05 '16, 4:15 a.m.
Why you r using set value function? Do you want to set a custom attribute?
Kenery Wang
commented May 05 '16, 4:19 a.m.
Exactly, set value for a custom attribute. I also try the other method like 'setDuration' for built-in attribute, failed either.
Hakki Bozkurt
commented May 05 '16, 4:23 a.m.
Can you comment "attribute_delayDays" definition from your code?
Kenery Wang
commented May 05 '16, 4:26 a.m.
IAttribute attribute_delayDays = fworkItemServer.findAttribute(workItem.getProjectArea(), "delay_days", null);
Michele Pegoraro
commented May 05 '16, 4:36 a.m.
Can you past here the exception you have?
Michele Pegoraro
commented May 05 '16, 4:39 a.m.
Have you tried to get your work item with the code I pasted?
Kenery Wang
commented May 05 '16, 4:56 a.m.
The Exception is shown as my own post Answer.
To Hakki, I believe that I got a real workingCopy since I can get attributes from it.
I'm not sure if it's possible to set value to attribute to work item in 'Asynchronous Tasks' so I post this question.
The huge difference between 'Asynchronous Tasks' and 'Operation Participant' is the later one involved user with role login first, while another one is not.
Michele Pegoraro
commented May 05 '16, 5:11 a.m.
Let me say that this is more a permission problem. You can always set that field modification permission set to everyone. Or, more likely, you can use ImpersonationService and run the save operation as a pre-configured user. I use this with the event handler (which is, basically, an asynchronous task runned by "admin" user) but I suppose you can use it too.
Kenery Wang
commented May 05 '16, 5:41 a.m.
I've checked the attribute has been set as everyone can modify it. I think it might not be the permission problem... Yes, you are right they are different from each other, but i think not huge.
You use IWorkItemServer in your AT and I use IWorkItemCommon my OP. They are doing same thing.
Can you try to set another custom attribute (string based)?
If you get same error, please try to replace this service:
instead of:
showing 5 of 11
show 6 more comments
|
16:43:40,026 [jazz: AsynchronousTaskRunner-2 @@ 16:41] ERROR com.ibm.team.repository - CRJAZ0852I An exception occurred while executing the task "Delay_Days_Monitor_taskID", contributed by component "com.ibm.team.repository". The task will be removed from the schedule.
org.eclipse.core.runtime.AssertionFailedException: assertion failed:
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:96)
at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.setValue(WorkItemImpl.java:2909)
at com.delta.workitem.asynchronousTask.DelayDaysMonitor.setAttribute(DelayDaysMonitor.java:207)
at com.delta.workitem.asynchronousTask.DelayDaysMonitor.findDelayWorkItem(DelayDaysMonitor.java:193)
at com.delta.workitem.asynchronousTask.DelayDaysMonitor.runTask(DelayDaysMonitor.java:103)
at com.ibm.team.repository.service.async.AbstractAutoScheduledTask.executeTask(AbstractAutoScheduledTask.java:96)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.eclipse.soda.sat.core.internal.record.ExportProxyServiceRecord.invoke(ExportProxyServiceRecord.java:361)
at org.eclipse.soda.sat.core.internal.record.ExportProxyServiceRecord.access$0(ExportProxyServiceRecord.java:347)
at org.eclipse.soda.sat.core.internal.record.ExportProxyServiceRecord$ExportedServiceInvocationHandler.invoke(ExportProxyServiceRecord.java:56)
at com.sun.proxy.$Proxy834.executeTask(Unknown Source)
at com.ibm.team.repository.service.internal.scheduler.AsynchronousTaskRunner.runTask(AsynchronousTaskRunner.java:185)
at com.ibm.team.repository.service.internal.scheduler.AsynchronousTaskRunner.run(AsynchronousTaskRunner.java:138)
at java.lang.Thread.run(Thread.java:761)
Comments
Michele Pegoraro
commented May 05 '16, 4:55 a.m.
If you look at the source code (WorkItemImpl.java), on that line you'll find this:
Kenery Wang
commented May 05 '16, 5:15 a.m.
What do you mean about 'try to synchronize it before run the task'? I'm pretty sure the work item I got (or workingCopy) contains the 'delay_days' attribute.
Michele Pegoraro
commented May 05 '16, 6:23 a.m.
I don't know, this is the reason of the error you have... basically it does not find an attribute if the work item has been created before the custom attribute has been added and the work item has not been synchronized (it is the operation that add new attribute to old work items, you can do it from eclipse client and probably also web client) or if the profile you're using is not correct. But as you're using IWorkItem.FULL_PROFILE this shouldn't be the case.
|
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.