Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Modify a WorkItem

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

0 votes



3 answers

Permanent link
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

0 votes


Permanent link
Hi, guys.
Thanks a lot. it is useful for me

0 votes


Permanent link
 The disconnect on the work item here is key ...thanks! Could not find that anywhere!

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,943

Question asked: Mar 29 '11, 2:24 p.m.

Question was seen: 7,138 times

Last updated: Apr 25 '14, 10:22 a.m.

Confirmation Cancel Confirm