It's all about the answers!

Ask a question

Modify a WorkItem


Susan Hanson (1.6k2201194) | asked Mar 29 '11, 2:24 p.m.
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

3 answers



permanent link
Ralph Schoon (63.5k33646) | answered Apr 04 '11, 4:49 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi Susan,

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

permanent link
HU Bin Hai (1111) | answered Apr 13 '11, 4:12 a.m.
Hi, guys.
Thanks a lot. it is useful for me

permanent link
Lori Ruffing (1758) | answered Apr 25 '14, 10:22 a.m.
 The disconnect on the work item here is key ...thanks! Could not find that anywhere!

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.