Jazz Register Log in
Jazz Forum Welcome to the Jazz Community Forum

Welcome to the Jazz Community Forum

Connect and collaborate with IBM Engineering experts and users

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.

0 votes



2 answers

Permanent link
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;
}
}


0 votes


Permanent link
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

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,993

Question asked: Jun 09 '11, 10:11 a.m.

Question was seen: 8,129 times

Last updated: Jun 09 '11, 10:11 a.m.

Confirmation Cancel Confirm