It's all about the answers!

Ask a question

How to Set Attribute of a Work Item in an Asynchrounous Task?


0
1
Kenery Wang (6411727) | asked May 05 '16, 3:18 a.m.
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



permanent link
Hakki Bozkurt (1631228) | answered May 05 '16, 3:42 a.m.
edited May 05 '16, 3:42 a.m.
Hello Kenery,
IWorkItem findWorkItem = workItemClient.findWorkItemById(currentWorkItemID, IWorkItem.FULL_PROFILE, monitor);
IWorkItemHandle wiHandle = (IWorkItemHandle) findworkItem.getItemHandle();
IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager(); 
wcm.connect(handle, IWorkItem.FULL_PROFILE, null); 
WorkItemWorkingCopy wc = wcm.getWorkingCopy(handle); 
IWorkItem wcWorkItem = wc.getWorkItem(); /* do whatever you want */ wc.save(monitor);


Comments
Kenery Wang commented May 05 '16, 3:47 a.m.

Hi Hakki,

Thanks so much for your reply. You provide a code snippet using client side API. Do you have the same example for server side API?


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)?




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'.


permanent link
Michele Pegoraro (1.8k14118103) | answered May 05 '16, 3:54 a.m.
edited May 05 '16, 3:55 a.m.
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
Kenery Wang commented May 05 '16, 4:01 a.m. | edited May 05 '16, 4:02 a.m.

 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?

IWorkItem
freshCopy = (IWorkItem)workItemService.findWorkItemById(wi.getId(), IWorkItem.FULL_PROFILE, null).getWorkingCopy();
 

The setValue method works correctly if the object is a real working copy. It seems like your object has something wrong if you get an exception...


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


Hakki Bozkurt commented May 05 '16, 6:52 a.m. | edited May 05 '16, 6:52 a.m.

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:
IWorkItemCommon workItemCommonService = (IWorkItemCommon) getService(IWorkItemCommon.class);
instead of:
IWorkItemServer fworkItemServer = getService(IWorkItemServer.class); 





showing 5 of 11 show 6 more comments

permanent link
Kenery Wang (6411727) | answered May 05 '16, 4:44 a.m.
 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:

Assert.isTrue(hasAttribute(attribute));

So, it seems that the work item that you're trying to set value to does not have that specific attribute. Did you try to synchronize it before run the task?


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


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.