Attribute customization - Calculated Values for enumeration list
Hello,
I've created a calculated value in JavaScript to update an custom attribute based on the value of the "Filed Against" field.
I can get the id but not the label. Is there another api to get the label? I'm using RTC 3.0.1.
var filedAgainst = workItem.value(WorkItemAttributes.FILED_AGAINST);
Or how can I convert the id to the display value?
Thanks in advance for your help
Accepted answer
I agree to William. workItem.getLabel(WorkItemAttributes.FILED_AGAINST); should give you the label of the category. See https://jazz.net/library/article/1093 Lab 5 for some guidance.
If the target attribute is an enumeration, you will however have to pass the literal ID to the enumeration and not the label.
If the target attribute is an enumeration, you will however have to pass the literal ID to the enumeration and not the label.
3 other answers
the label is stored in the workflowInfo data item.
this code is in a plugin, but same deal
fix this --> IAuditableCommon iac = p.getSaveOperationParameter().getAuditableCommon();
WorkflowManager wfm = new WorkflowManager(iac);
if(false)
{
IWorkItemCommon workItemCommon = iac.getPeer(IWorkItemCommon.class);
// loop thru all the attributes in the project
// attributes are project wide, not workitem specific
for(IAttribute ia:workItemCommon.findAttributes(p.getOldProcessArea().getProjectArea(), monitor) )
{
// if this attribute is available on this workitem
if(workItem.hasAttribute(ia))
{
System.out.println("processing for variable="+ia.getDisplayName()+" attrib type="+ia.getAttributeType());
try
{
// attempt to get the enumeration literal for this attribute
// will throw exception if not an enum
IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>)workItemCommon.resolveEnumeration(ia, monitor);
if(enumeration!=null)
{
// get the literal specifically
String[] iaval = ia.getValue(iac, workItem, monitor).toString().split(":");
// if present
if(iaval.length>1 && iaval[1]!=null)
{
// loop thru the literal to value mappings
for (ILiteral literal : enumeration.getEnumerationLiterals())
{
// if this literal matches the attribute value
if(literal.getIdentifier2().getStringIdentifier().equalsIgnoreCase(iaval[1]))
{
// display the usable name
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());
}
}
}
this code is in a plugin, but same deal
fix this --> IAuditableCommon iac = p.getSaveOperationParameter().getAuditableCommon();
WorkflowManager wfm = new WorkflowManager(iac);
if(false)
{
IWorkItemCommon workItemCommon = iac.getPeer(IWorkItemCommon.class);
// loop thru all the attributes in the project
// attributes are project wide, not workitem specific
for(IAttribute ia:workItemCommon.findAttributes(p.getOldProcessArea().getProjectArea(), monitor) )
{
// if this attribute is available on this workitem
if(workItem.hasAttribute(ia))
{
System.out.println("processing for variable="+ia.getDisplayName()+" attrib type="+ia.getAttributeType());
try
{
// attempt to get the enumeration literal for this attribute
// will throw exception if not an enum
IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>)workItemCommon.resolveEnumeration(ia, monitor);
if(enumeration!=null)
{
// get the literal specifically
String[] iaval = ia.getValue(iac, workItem, monitor).toString().split(":");
// if present
if(iaval.length>1 && iaval[1]!=null)
{
// loop thru the literal to value mappings
for (ILiteral literal : enumeration.getEnumerationLiterals())
{
// if this literal matches the attribute value
if(literal.getIdentifier2().getStringIdentifier().equalsIgnoreCase(iaval[1]))
{
// display the usable name
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());
}
}
}
}