Set a new value to an attribute of a WorkItem with Java Plain API
Tiago Fernandez (53●5●16●19)
| asked Aug 14 '13, 1:23 p.m.
edited Oct 15 '14, 9:33 a.m. by Ralph Schoon (63.3k●3●36●46)
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.
|
Maybe you need to add something like this before calling setValue?
if (!workItem_to_edit.hasAttribute(iAttribute)) { workItem_to_edit.addCustomAttribute(iAttribute) } Comments I did a println of the workItem_to_edit.hasAttribute(iAttribute) and it returned false.
The workingCopy seems it did get all attributes from the original workItem, I suspect that this line could be the key:
Thanks. PS: I am sure that the original workItem has the attribute I am trying to setValue, but the workCopy doesn't have it :( This has gone well beyond what I know. The best I can do right now is speculate.
I'd print out hasAttribute on the original item to be certain it was there. Maybe workitems don't start out with all of the attributes?
Tiago Fernandez
commented Sep 14 '13, 12:12 p.m.
Hello again,
What can be happening that it lists twice some attibutes?
Thanks. |
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.
|
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.
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....