I'm trying to write a Java tool to set a custom attribute on a jazz work item.
The custom attribute has following definition:
Name: Phase Found
Type: HowFound (Enumeration)
ID: howfound`
Literals for HowFound
:
Name: Automation
Name: Testing
This is the Java code which tries to set the custom attribute's value.
Note: log.info("Phase found: workitem has attribute");
is printed, so I know it finds the attribute, just cannot set value.
public class WorkItemInitialization extends WorkItemOperation {
private static Logger log = Logger.getLogger(WorkItemInitialization.class.getName());
public WorkItemInitialization(ICategoryHandle filedAgainst) {
super("Initializing Work Item");
}
protected void execute(WorkItemWorkingCopy workingCopy, IProgressMonitor monitor) throws TeamRepositoryException {
log.info("Executing work item changes.");
IWorkItem workItem = workingCopy.getWorkItem();
IWorkItemClient workItemClient = (IWorkItemClient) Main.repo.getClientLibrary(IWorkItemClient.class);
IAttribute phaseFound = workItemClient.findAttribute(Main.projectAreaRTC, "howfound", monitor);
if (workItem.hasCustomAttribute(phaseFound)){
log.info("Phase found: workitem has attribute");
IEnumeration<? extends ILiteral> myEnumeration = workItemClient.resolveEnumeration(phaseFound, monitor);
ILiteral targetLiteral = null;
for(ILiteral literal : myEnumeration.getEnumerationLiterals()) {
if(literal.getName().equals("Automation")) {
targetLiteral = literal;
}
}
workItem.setValue(phaseFound, targetLiteral);
}
}
}
This is the error I get when running:
Exception in thread "main" java.lang.ClassCastException: com.ibm.team.workitem.common.internal.model.ConfigurationItem incompatible with com.ibm.team.workitem.common.model.Identifier
at com.ibm.team.workitem.common.internal.model.impl.WorkItemImpl.setValue(WorkItemImpl.java:2945)