Programmatic read value of custom attributes
Hi all,
i need to read custom attributes value: i wrote some code but i get always the same error ( using working copy too ):
this is my code to read the value:
Thanks
i need to read custom attributes value: i wrote some code but i get always the same error ( using working copy too ):
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.getValue(WorkItemImpl.java:2848)
at com.ibm.team.workitem.common.internal.attributeValueProviders.FallbackProvider.getValue(FallbackProvider.java:31)
at com.ibm.team.workitem.common.internal.model.impl.AttributeImpl.getValue(AttributeImpl.java:899)
this is my code to read the value:
IWorkItemServer workItemServer = getService(IWorkItemServer.class);
IWorkItem workingCopyItem = (IWorkItem) wi.getWorkingCopy();
parameterString += "\"workItemId:"+wi.getId()+"|";
parameterString += "project:"+workItemServer.findAttribute(workingCopyItem.getProjectArea(), "project", monitor).getValue(iac, workingCopyItem, monitor)+"|";
IAC is IAuditableCommon
monitor is ProgressMonitor
The code is in an OperationParticipant
Thanks
3 answers
Hi,
first you have to retrieve the attribute using findAttribute method, and then you have to use IWorkItem.getValue(IAttribute) method, casting the returned value (if it is an enumeration is quite more complex).
Before the getValue maybe you want to run the IWorkItem.hasAttribute(IAttribute) in order to be sure that the work-item has the attribute you need.
Best Regards,
Michele.
first you have to retrieve the attribute using findAttribute method, and then you have to use IWorkItem.getValue(IAttribute) method, casting the returned value (if it is an enumeration is quite more complex).
Before the getValue maybe you want to run the IWorkItem.hasAttribute(IAttribute) in order to be sure that the work-item has the attribute you need.
Best Regards,
Michele.
If you use the client API this is described here: http://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/
If you use a server API, here are examples http://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/
You use the ID of the custom attribute to find the IAttribute.
Basically you find the IAttribute using the ID and then getValue() the value and cast it to a matching type.
If you use a server API, here are examples http://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/
You use the ID of the custom attribute to find the IAttribute.
Basically you find the IAttribute using the ID and then getValue() the value and cast it to a matching type.