Welcome to the Jazz Community Forum
Set Custom Timestamp Attribute Value Programmatically

Hi everyone,
I'm trying to set a customized Timestamp field via the 4.0.1 plain java API. We have some imported work items which are displaying a resolution date as the date of their import, and it does not appear that I can modify this field, which is why I have made my own.
The code is as follows:
IAttribute att = null;
att = workItemClient.findAttribute(projectArea, "ImportedResolutionDate", null);
Timestamp timeStamp = workItem.getResolutionDate();
System.out.println(att.getIdentifier());
System.out.println(att.getAttributeType());
if(att != null){
if(workItem.hasCustomAttribute(att)){
workItem.setValue(att, timeStamp);
}else{
throw new Exception("Work item does not have attribute " + att);
}
}else{
throw new Exception("Attribute is null");
}
So, I'm trying to set the value of my attribute - which has an ID of ImportedResolutionDate - to the existing resolution date (for testing purposes. This will eventually be expanded to pull the correct data from a database, but for now I wanted easy access to a value). When the code hits the line where the value is set, I get the following error:
Wed Jan 30 13:53:02 EST 2013 ERROR - null
class com.ibm.team.repository.common.internal.ImmutablePropertyException
com.ibm.team.repository.common.internal.ImmutablePropertyException
at com.ibm.team.repository.common.internal.util.ItemUtil$ProtectAdapter.notifyChanged(ItemUtil.java:2051)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:380)
at com.ibm.team.repository.common.model.impl.TimestampExtensionEntryImpl.setTypedValue(TimestampExtensionEntryImpl.java:180)
at com.ibm.team.repository.common.model.impl.TimestampExtensionEntryImpl.setValue(TimestampExtensionEntryImpl.java:362)
at org.eclipse.emf.common.util.BasicEMap.putEntry(BasicEMap.java:303)
at org.eclipse.emf.common.util.BasicEMap.put(BasicEMap.java:584)
at org.eclipse.emf.common.util.BasicEMap$DelegatingMap.put(BasicEMap.java:799)
at com.ibm.team.repository.common.model.impl.ItemImpl.setTimestampExtension(ItemImpl.java:1253)
at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.setValue(WorkItemImpl.java:2938)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.ibm.team.repository.common.internal.util.ItemStore$ItemInvocationHandler.invoke(ItemStore.java:597)
at $Proxy16.setValue(Unknown Source)
at <various lines in my classes>
So the attribute exists in the project area, I can call various get methods on the attribute and it returns the correct information, the work item is of a type which uses the attribute, and I do not see anywhere the attribute itself is set to be readonly or anything else that makes me think it is immutable. Anyone seen this before?
I'm trying to set a customized Timestamp field via the 4.0.1 plain java API. We have some imported work items which are displaying a resolution date as the date of their import, and it does not appear that I can modify this field, which is why I have made my own.
The code is as follows:
IAttribute att = null;
att = workItemClient.findAttribute(projectArea, "ImportedResolutionDate", null);
Timestamp timeStamp = workItem.getResolutionDate();
System.out.println(att.getIdentifier());
System.out.println(att.getAttributeType());
if(att != null){
if(workItem.hasCustomAttribute(att)){
workItem.setValue(att, timeStamp);
}else{
throw new Exception("Work item does not have attribute " + att);
}
}else{
throw new Exception("Attribute is null");
}
So, I'm trying to set the value of my attribute - which has an ID of ImportedResolutionDate - to the existing resolution date (for testing purposes. This will eventually be expanded to pull the correct data from a database, but for now I wanted easy access to a value). When the code hits the line where the value is set, I get the following error:
Wed Jan 30 13:53:02 EST 2013 ERROR - null
class com.ibm.team.repository.common.internal.ImmutablePropertyException
com.ibm.team.repository.common.internal.ImmutablePropertyException
at com.ibm.team.repository.common.internal.util.ItemUtil$ProtectAdapter.notifyChanged(ItemUtil.java:2051)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:380)
at com.ibm.team.repository.common.model.impl.TimestampExtensionEntryImpl.setTypedValue(TimestampExtensionEntryImpl.java:180)
at com.ibm.team.repository.common.model.impl.TimestampExtensionEntryImpl.setValue(TimestampExtensionEntryImpl.java:362)
at org.eclipse.emf.common.util.BasicEMap.putEntry(BasicEMap.java:303)
at org.eclipse.emf.common.util.BasicEMap.put(BasicEMap.java:584)
at org.eclipse.emf.common.util.BasicEMap$DelegatingMap.put(BasicEMap.java:799)
at com.ibm.team.repository.common.model.impl.ItemImpl.setTimestampExtension(ItemImpl.java:1253)
at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.setValue(WorkItemImpl.java:2938)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.ibm.team.repository.common.internal.util.ItemStore$ItemInvocationHandler.invoke(ItemStore.java:597)
at $Proxy16.setValue(Unknown Source)
at <various lines in my classes>
So the attribute exists in the project area, I can call various get methods on the attribute and it returns the correct information, the work item is of a type which uses the attribute, and I do not see anywhere the attribute itself is set to be readonly or anything else that makes me think it is immutable. Anyone seen this before?
Accepted answer

Hi Joshua,
These forum posts suggest getting a working copy of the work item and then saving that mutable copy: https://jazz.net/forum/questions/62091/getting-immutablepropertyexception-while-modifying-workitem and https://jazz.net/forum/questions/11143/programmatically-adding-a-comment-to-a-work-item.
These forum posts suggest getting a working copy of the work item and then saving that mutable copy: https://jazz.net/forum/questions/62091/getting-immutablepropertyexception-while-modifying-workitem and https://jazz.net/forum/questions/11143/programmatically-adding-a-comment-to-a-work-item.