Question

I am trying to set the value of "Discussion" at work item pragmatically.

I managed to set the "Description" attribute but when I tried to set the Discussion I got null pointer exception :

  IWorkItemClient workItemClient= (IWorkItemClient)repository.getClientLibrary(IWorkItemClient.class);
 IWorkItemWorkingCopyManager manager= workItemClient.getWorkItemWorkingCopyManager();
 manager.connect(workItem, IWorkItem.SMALL_PROFILE, SysoutProgressMonitor.getMonitor());
 WorkItemWorkingCopy wc= manager.getWorkingCopy(workItem);

  IProgressMonitor monitor = SysoutProgressMonitor.getMonitor();
  IWorkItemClient service = (IWorkItemClient) repository.getClientLibrary(IWorkItemClient.class);

   IAttribute discussionAttribute = service.findAttribute(projectArea, "discussion", monitor);//Here I got  a null "discussionAttribute"?

   wc.getWorkItem().setValue(discussionAttribute, "New Value for Discussion");

Any ideas!

Was it helpful?

Solution

//Here I got a null "discussionAttribute"?
Attribute discussionAttribute = service.findAttribute(projectArea, "discussion", monitor);

I suspect "discussion" isn't a valid WorkItem attribute id.

Try the question "Where can I find a list of IWorkItem attributes" to query all the attributes of the work item, in order to get the correct attribute name for "discussion" (maybe "comments"?)

Use IItemManager.fetchCompleteItem to fetch the item for any handle.
The items carry the actual info; the handles are essentially just like pointers / URLs.

For example:

IContributorHandle contributorHandle = ...

IContributor contributor = (IContributor) teamRepository.itemManager.fetchCompleteItem(contributorHandle, IItemManager.DEFAULT, null);  // should really provide a progress monitor in last arg for progress / cancelaton

String name = contributor.getName();

That's for client-side. For server-side, use IRepositoryItemService to fetch the item.


In the attributes of the project area configuration, I see

"Comments": ID "com.ibm.team.workitem.attribute.comments", but no "discussion".

On Jazz.net, you find a link to this discussion and mentions an id named "internalComments".

Try then:

Attribute discussionAttribute = 
  service.findAttribute(projectArea, "internalComments", monitor);

Don't forget to save your modified Work Item though, as in "Modify a WorkItem"

IDetailedStatus s = wc.save(null);
if (!s.isOK()) {
    throw new TeamRepositoryException("Error saving work item",
                                      s.getException());
}

OTHER TIPS

This is the final resolution and it works :) Thanks to VonC & Sam.

IWorkItemClient workItemClient= (IWorkItemClient)repository.getClientLibrary(IWorkItemClient.class);
         IWorkItemWorkingCopyManager manager= workItemClient.getWorkItemWorkingCopyManager();
         manager.connect(workItem, IWorkItem.SMALL_PROFILE, SysoutProgressMonitor.getMonitor());
         WorkItemWorkingCopy wc= manager.getWorkingCopy(workItem);

         IAttribute commentsAttr =  findAttribute(repository, projectArea, "internalComments");
         IComments comments= wc.getWorkItem().getComments();
         IComment comment= comments.createComment( repository.loggedInContributor(),
                 XMLString.createFromPlainText( "Aloo from Mars"));                 

            comments.append(comment); 

            wc.save(null);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top