It's all about the answers!

Ask a question

How to get the value selected by user from a drop-down list


Heng Kuang (11) | asked May 03 '12, 12:38 p.m.
We defined an attribute of a work item. The value of this attribute will be selected from a drop-down list which contains 3 options. However, no matter we select which option, the API always return:

com.ibm.team.workitem.common.model.ILiteral:com.ibm.team.workitem.servicechange.targetrelease.literal.l4

after we executed:

iattribute = workItemClient.findAttribute(projectArea, attributeID , null);
Object attribute = workItem.getValue(iattribute);

It suppose to return:

com.ibm.team.workitem.common.model.ILiteral:com.ibm.team.workitem.servicechange.targetrelease.literal.l2

or

com.ibm.team.workitem.common.model.ILiteral:com.ibm.team.workitem.servicechange.targetrelease.literal.l4

or

com.ibm.team.workitem.common.model.ILiteral:com.ibm.team.workitem.servicechange.targetrelease.literal.l6

depends on which option we selected.

Any idea to solve this issue? Thanks!

6 answers



permanent link
sam detweiler (12.5k6195201) | answered May 03 '12, 2:54 p.m.
WHEN are u looking at the value? and in what code?

is this an Advisor (before the change is made), or a Participant?

and why are u locating the variable directly from the client (if either of the above) as the value should be supplied in the state passed as part of the advisor/participant run() call.

you ARE looking at its PROPOSED new value.. in an advisor.

in my advisor

ISaveParameter p = (ISaveParameter)data;
// get the affected object
IAuditable auditable = p.getNewState();


gets me the workitem in the NEW proposed state (but not yet saved on disk.. that is the OLD state)

permanent link
sam detweiler (12.5k6195201) | answered May 03 '12, 3:00 p.m.
here is code I just added to my advisor to determine the values of all the attributes in the affected workitem

ISaveParameter p = (ISaveParameter)data;
// get the affected object
IAuditable auditable = p.getNewState();
// reference the right object type (cast)
IWorkItem workItem = (IWorkItem) auditable;
IAuditableCommon iac = p.getSaveOperationParameter().getAuditableCommon();
IWorkItemCommon workItemCommon = iac.getPeer(IWorkItemCommon.class);
//List<IAttributeHandle> wi_attribs = workItem.getCustomAttributes();
for(IAttribute ia:workItemCommon.findAttributes(p.getOldProcessArea().getProjectArea(), monitor) )
{
if(workItem.hasAttribute(ia))
{
System.out.println("processing for variable="+ia.getDisplayName()+" attrib type="+ia.getAttributeType());
try
{
// this will throw exception if not enumeration
IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>)workItemCommon.resolveEnumeration(ia, monitor);
if(enumeration!=null)
{
String[] iaval = ia.getValue(iac, workItem, monitor).toString().split(":");

if(iaval.length>1 && iaval[1]!=null)
{
List<ILiteral> enumerationLiterals = enumeration.getEnumerationLiterals();
for (ILiteral literal : enumerationLiterals)
{
if(literal.getIdentifier2().getStringIdentifier().equalsIgnoreCase(iaval[1]))
{
System.out.println("attribute name="+ia.getIdentifier() +", type"+"="+ia.getAttributeType()+" literal="+literal.getIdentifier2().getStringIdentifier()+" literal name="+literal.getName());
break;
}
}
}
}
}
catch (Exception e)
{
//System.out.println("Exception="+e.toString());
}
}
}

permanent link
Kelvin Lui (51299) | answered May 04 '12, 9:44 a.m.
We developed a client side code. Basically we ran a query to retrieve the list of workitem. And with each workitem we use the IWorkITEM API to retrieve the value of each attribute associated with the workitem.

The attribute is defined as an enumeration (a list of option) and user can select one of the option in the dropdown box. The selected value is saved prior to the client side code running and retrieving the value.

Here is the code that we use to retrieve the attribute.

public Object getAttributefromWorkItem(IWorkItem workItem, String attributeID) throws TeamRepositoryException
{
IAttribute iattribute = null;

/*
* sample attribute ID
* "com.ibm.team.workitem.target.businesscontrol";
* "com.ibm.team.target.upreleasetrack";
* "com.ibm.team.workitem.presentation.approvals";
*/
try
{
iattribute = workItemClient.findAttribute(projectArea, attributeID , null);
}
catch (Exception e)
{
System.out.println("RTC: Failed to return attribute object due to " + e.toString());
}

Object attribute = workItem.getValue(iattribute);
//System.out.println ("Customized attribute1 : " + attribute.toString());
return attribute;
}



here is code I just added to my advisor to determine the values of all the attributes in the affected workitem

ISaveParameter p = (ISaveParameter)data;
// get the affected object
IAuditable auditable = p.getNewState();
// reference the right object type (cast)
IWorkItem workItem = (IWorkItem) auditable;
IAuditableCommon iac = p.getSaveOperationParameter().getAuditableCommon();
IWorkItemCommon workItemCommon = iac.getPeer(IWorkItemCommon.class);
//List<IAttributeHandle> wi_attribs = workItem.getCustomAttributes();
for(IAttribute ia:workItemCommon.findAttributes(p.getOldProcessArea().getProjectArea(), monitor) )
{
if(workItem.hasAttribute(ia))
{
System.out.println("processing for variable="+ia.getDisplayName()+" attrib type="+ia.getAttributeType());
try
{
// this will throw exception if not enumeration
IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>)workItemCommon.resolveEnumeration(ia, monitor);
if(enumeration!=null)
{
String[] iaval = ia.getValue(iac, workItem, monitor).toString().split(":");

if(iaval.length>1 && iaval[1]!=null)
{
List<ILiteral> enumerationLiterals = enumeration.getEnumerationLiterals();
for (ILiteral literal : enumerationLiterals)
{
if(literal.getIdentifier2().getStringIdentifier().equalsIgnoreCase(iaval[1]))
{
System.out.println("attribute name="+ia.getIdentifier() +", type"+"="+ia.getAttributeType()+" literal="+literal.getIdentifier2().getStringIdentifier()+" literal name="+literal.getName());
break;
}
}
}
}
}
catch (Exception e)
{
//System.out.println("Exception="+e.toString());
}
}
}

permanent link
Nick Edgar (6.5k711) | answered May 04 '12, 11:22 a.m.
JAZZ DEVELOPER
Is your client-side program long-running? Is it possible it has an old state of the work item cached? If so, try using the IItemManager.REFRESH flag when fetching the work item. You might also want to print out the work item id (IWorkItem.getId()) to be sure you're actually dealing with the work item you think you are.

permanent link
Kelvin Lui (51299) | answered May 04 '12, 4:17 p.m.
Hi Nick,

We are using the IQueryCommon. getResolvedExpressionResults()to retrieve the list of workItem object, rather than using the IItemManager.fetchCompleteItemsPermissionAware() , where you can set itemManager.REFRESH as the second parameter.

Would IQueryCommon. getResolvedExpressionResults() always return the latest state of the work item?

Thanks.


Is your client-side program long-running? Is it possible it has an old state of the work item cached? If so, try using the IItemManager.REFRESH flag when fetching the work item. You might also want to print out the work item id (IWorkItem.getId()) to be sure you're actually dealing with the work item you think you are.

permanent link
Nick Edgar (6.5k711) | answered May 04 '12, 4:34 p.m.
JAZZ DEVELOPER
getResolvedExpressionResults uses
com.ibm.team.workitem.client.internal.AuditableClient.resolveAuditables(List<extends>, ItemProfile<T>, IProgressMonitor)
to fetch items (when on the client side). It uses IItemManager.DEFAULT, not REFRESH, so it will return cached items.

This is only an issue if your program is long-running. You could try using IItemManager (obtained via ITeamRepository.itemManager()) to re-fetch the items, specifying REFRESH, to see if stale cached data is the issue.

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.