Set a new value to an attribute of a WorkItem with Java Plain API
![]()
Tiago Fernandez (53●3●16●19)
| asked Aug 14 '13, 1:23 p.m.
edited Oct 15 '14, 9:33 a.m. by Ralph Schoon (61.8k●3●36●43)
Hello, I am brand new with Java Plain API and I am trying to set a new Value to an attibute of a workItem.
Part of the code I have is (I already have the workItem and the iAttribute varibales):
def copyManager = workItemClient.getWorkItemWorkingCopyManager();
but I get the following error:
Caught: org.eclipse.core.runtime.AssertionFailedException: assertion failed:
What am I doing wrong? Thanks for the help. |
4 answers
![]()
If you have a custom attribute, you probably want to try this -
List<IAttributeHandle> customAttributes = workItem.getCustomAttributes();If this list of attributes contains your attribute, you can call workItem.setValue(attribute, value);Otherwise, first add attribute and then set value workitem.addCustomAttribute(attribute); workItem.setValue(attribute, value); |
![]() More details of how my code is:
workItem = workItemClient.findWorkItemById(workItemNumber, IWorkItem.FULL_PROFILE, new SysoutProgressMonitor())
println("Listing all attributes....")
def iAttributeHandle = (IAttributeHandle) iterator.next()
}
I want to set an Integer value to a custom field of a WorkItem "Actual Spent Hours", and the iAttribute is obtained by doing a for of the result of workItemClient.findAttributes.
Since I am parsing all attributes in this case, is it necessary to do an hasAttribute()?
As always, Thanks for the help :) Comments If you don't check if the attribute is there with hasAttribute you can get an error. If all work item types you work with have the attribute, you don't have an issue. The attributes available to the type are not necessarily all there, especially on old items created before the attribute has been created. You would have to synchronize the attributes to make sure.
|
![]()
Hi,
There might be more than one attribute called "Actual Spent Hours".
Have you checked to see if the attribute ID is the same on the "duplicates" by calling getIdentifier() ?
The identifier is unique within a project area, the name of the attribute is not.
|
Comments
A failure with that stack trace means there is no attribute by checking hasAttribute() (yes, the error could be much better).
Where did the value of iAttribute come from? Maybe it is not applicable to that work item's type?
I will show more details of my code, but as an answer since it doesn't fit as a comment....