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

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!

1

0 votes



3 answers

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

0 votes

Comments

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?

Hello Kenery,


Yes I have, what are you trying to do? Operation Participant (server side plugin)?



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

0 votes

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

 Why you r using set value function? Do you want to set a custom attribute?

 Exactly, set value for a custom attribute. I also try the other method like 'setDuration' for built-in attribute, failed either. 

Can you comment "attribute_delayDays" definition from your code?

IAttribute attribute_delayDays = fworkItemServer.findAttribute(workItem.getProjectArea(), "delay_days", null);

Can you past here the exception you have?

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

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.

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.

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





showing 5 of 11 show 6 more comments

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

0 votes

Comments

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?

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.

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

Question asked: May 05 '16, 3:18 a.m.

Question was seen: 2,549 times

Last updated: May 05 '16, 6:52 a.m.

Confirmation Cancel Confirm