Modify a WorkItem
![](http://jazz.net/_images/myphoto/66e177e2048ef539f521aa8ee20ae030.jpg)
I have tried to look around for this and never really found something that helped me.
I have a WorkItemID (like 33338) and I want to change a single attribute programmatically.
final ITeamRepository repository = app.login ();
final IWorkItemClient workItemClient = app.clientLibrary (IWorkItemClient.class);
for (final String arg : args) {
System.out.println("looking up work item " + arg);
final IWorkItem workItem = workItemClient.findWorkItemById(Integer.parseInt (arg), IWorkItem.FULL_PROFILE, app.getMonitor ());
WorkItemWorkingCopy workingCopy = (WorkItemWorkingCopy)workItem.getWorkingCopy();
final List<IAttribute> attributes = app.getAttributes (workItem);
for (int i = 0; i < attributes.size (); i++) {
IAttribute attr = attributes.get(i);
System.out.println(attr.getIdentifier());
if (attr.getIdentifier().equals("sort")){
workItem.setValue(attr,new Integer("99999"));
}
}
IDetailedStatus status = workingCopy.save(app.getMonitor ());
I was hoping this work work, since it is similar to what I used to programmatically create work items. However, I get a classCastException on this line:
WorkItemWorkingCopy workingCopy = (WorkItemWorkingCopy)workItem.getWorkingCopy();
But if I keep it as IWorkItem workingCopy = (IWorkItem)workItem.getWorkingCopy();
Then my workingCopy.save(monitor) method doesn't exist.
Susan
I have a WorkItemID (like 33338) and I want to change a single attribute programmatically.
final ITeamRepository repository = app.login ();
final IWorkItemClient workItemClient = app.clientLibrary (IWorkItemClient.class);
for (final String arg : args) {
System.out.println("looking up work item " + arg);
final IWorkItem workItem = workItemClient.findWorkItemById(Integer.parseInt (arg), IWorkItem.FULL_PROFILE, app.getMonitor ());
WorkItemWorkingCopy workingCopy = (WorkItemWorkingCopy)workItem.getWorkingCopy();
final List<IAttribute> attributes = app.getAttributes (workItem);
for (int i = 0; i < attributes.size (); i++) {
IAttribute attr = attributes.get(i);
System.out.println(attr.getIdentifier());
if (attr.getIdentifier().equals("sort")){
workItem.setValue(attr,new Integer("99999"));
}
}
IDetailedStatus status = workingCopy.save(app.getMonitor ());
I was hoping this work work, since it is similar to what I used to programmatically create work items. However, I get a classCastException on this line:
WorkItemWorkingCopy workingCopy = (WorkItemWorkingCopy)workItem.getWorkingCopy();
But if I keep it as IWorkItem workingCopy = (IWorkItem)workItem.getWorkingCopy();
Then my workingCopy.save(monitor) method doesn't exist.
Susan
3 answers
![](http://jazz.net/_images/myphoto/66e177e2048ef539f521aa8ee20ae030.jpg)
Hi Susan,
after a bit of searching this forum the following code does the trick for me:
I followed some links in http://jazz.net/forums/viewtopic.php?t=15608 and had some ancient code.
Thanks,
Ralph
after a bit of searching this forum the following code does the trick for me:
int id = new Integer(idString).intValue();
IWorkItem workItem = workItemClient.findWorkItemById(id, IWorkItem.SMALL_PROFILE, null);
IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager();
wcm.connect(workItem, IWorkItem.FULL_PROFILE, null);
try {
WorkItemWorkingCopy wc = wcm.getWorkingCopy(workItem);
wc.getWorkItem().setHTMLSummary(XMLString.createFromPlainText(summary));
IDetailedStatus s = wc.save(null);
if (!s.isOK()) {
throw new TeamRepositoryException("Error saving work item",
s.getException());
}
} finally {
wcm.disconnect(workItem);
}
I followed some links in http://jazz.net/forums/viewtopic.php?t=15608 and had some ancient code.
Thanks,
Ralph
I have tried to look around for this and never really found something that helped me.
I have a WorkItemID (like 33338) and I want to change a single attribute programmatically.
final ITeamRepository repository = app.login ();
final IWorkItemClient workItemClient = app.clientLibrary (IWorkItemClient.class);
for (final String arg : args) {
System.out.println("looking up work item " + arg);
final IWorkItem workItem = workItemClient.findWorkItemById(Integer.parseInt (arg), IWorkItem.FULL_PROFILE, app.getMonitor ());
WorkItemWorkingCopy workingCopy = (WorkItemWorkingCopy)workItem.getWorkingCopy();
final List<IAttribute> attributes = app.getAttributes (workItem);
for (int i = 0; i < attributes.size (); i++) {
IAttribute attr = attributes.get(i);
System.out.println(attr.getIdentifier());
if (attr.getIdentifier().equals("sort")){
workItem.setValue(attr,new Integer("99999"));
}
}
IDetailedStatus status = workingCopy.save(app.getMonitor ());
I was hoping this work work, since it is similar to what I used to programmatically create work items. However, I get a classCastException on this line:
WorkItemWorkingCopy workingCopy = (WorkItemWorkingCopy)workItem.getWorkingCopy();
But if I keep it as IWorkItem workingCopy = (IWorkItem)workItem.getWorkingCopy();
Then my workingCopy.save(monitor) method doesn't exist.
Susan