It's all about the answers!

Ask a question

How to use the getValue(IAttribute) method on IWorkItem?


Kamal Suruguchi (15112114) | asked Jun 09 '11, 10:11 a.m.
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



permanent link
Megan Katysovas (7665) | answered Jun 13 '11, 3:07 p.m.
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;
}
}



permanent link
Kamal Suruguchi (15112114) | answered Jun 17 '11, 5:16 a.m.
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

Your answer


Register or to post 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.