1

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!

4

2 回答 2

1

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

我怀疑“ discussion”不是有效的 WorkItem 属性 ID。

尝试“我在哪里可以找到IWorkItem属性列表”这个问题来查询工作项的所有属性,以便获得“”的正确属性名称discussion(也许是“ comments”?)

用于IItemManager.fetchCompleteItem获取任何句柄的项目。
物品携带实际信息;句柄本质上就像指针/ URL。

例如:

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();

那是给客户端的。对于服务器端,使用 IRepositoryItemService 来获取项目。


在项目区域配置的属性中,我看到

“评论”:ID “com.ibm.team.workitem.attribute.comments”,但没有“讨论”。

Jazz.net 上,您可以找到指向此讨论的链接,并提到了一个名为“ internalComments”的 id。

那就试试吧:

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

不过不要忘记保存修改后的工作项,如“修改工作项

IDetailedStatus s = wc.save(null);
if (!s.isOK()) {
    throw new TeamRepositoryException("Error saving work item",
                                      s.getException());
}
于 2013-05-13T13:22:00.623 回答
1

这是最终的解决方案,它有效 :) 感谢 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);
于 2013-05-13T18:50:12.420 回答