Welcome to the Jazz Community Forum
How to use the getValue(IAttribute) method on IWorkItem?

Are there any examples or instructions for using the getValue(IAttribute) on IWorkItem? I am unable to get hold of an instance of IAttribute to use this method. I had tried using IQueryableAttribute instance but that does not work as it does not seem to be of IAttribute type. Any help is appreciated. Thanks in advance.
2 answers

I've used the getValue to return the literal names for different enumerations based on the attribute id.
/*
* Story Points
*/
Object ob;
IAttribute attribute = findAttribute("com.ibm.team.apt.attribute.complexity");
boolean exists = iWorkItem.hasCustomAttribute(attribute);
if(exists){
ob = iWorkItem.getValue(attribute);
if(!(ob == null)) {
String longLiteralId = ob.toString();
int litSub = longLiteralId.indexOf(":");
String literalId = longLiteralId.substring(litSub+1);
String name = getLiteralName(attribute,literalId);
}
}
/*
* Returns attribute based on attribute Id. Returns null if doesn't exist
*/
public static IAttribute findAttribute(String attributeId){
try{
IAttribute attribute = iworkItemClientService.findAttribute(projectArea, attributeId, monitor);
return attribute;
}catch (TeamRepositoryException e) {
// TODO Auto-generated catch block
log.info(e.toString());
e.printStackTrace();
return null;
}
}
public static String getLiteralName(IAttribute attribute, String literalId){
IEnumeration<ILiteral> enumeration;
try {
enumeration = (IEnumeration<ILiteral>)iworkItemClientService.resolveEnumeration(attribute, null);
List<ILiteral> enumerationLiterals = enumeration.getEnumerationLiterals();
for (ILiteral literal : enumerationLiterals) {
if (literal.getIdentifier2().getStringIdentifier().equalsIgnoreCase(literalId)) {
return literal.getName();
}
}
return null;
} catch (Exception e) {
log.info(e.toString());
return null;
}
}

I've used the getValue to return the literal names for different enumerations based on the attribute id.
/*
* Story Points
*/
Object ob;
IAttribute attribute = findAttribute("com.ibm.team.apt.attribute.complexity");
boolean exists = iWorkItem.hasCustomAttribute(attribute);
if(exists){
ob = iWorkItem.getValue(attribute);
if(!(ob == null)) {
String longLiteralId = ob.toString();
int litSub = longLiteralId.indexOf(":");
String literalId = longLiteralId.substring(litSub+1);
String name = getLiteralName(attribute,literalId);
}
}
/*
* Returns attribute based on attribute Id. Returns null if doesn't exist
*/
public static IAttribute findAttribute(String attributeId){
try{
IAttribute attribute = iworkItemClientService.findAttribute(projectArea, attributeId, monitor);
return attribute;
}catch (TeamRepositoryException e) {
// TODO Auto-generated catch block
log.info(e.toString());
e.printStackTrace();
return null;
}
}
public static String getLiteralName(IAttribute attribute, String literalId){
IEnumeration<ILiteral> enumeration;
try {
enumeration = (IEnumeration<ILiteral>)iworkItemClientService.resolveEnumeration(attribute, null);
List<ILiteral> enumerationLiterals = enumeration.getEnumerationLiterals();
for (ILiteral literal : enumerationLiterals) {
if (literal.getIdentifier2().getStringIdentifier().equalsIgnoreCase(literalId)) {
return literal.getName();
}
}
return null;
} catch (Exception e) {
log.info(e.toString());
return null;
}
}
thanks Megan