Attempting to add comment to work item - comments are not added
I've created a groovy framework that accesses the Java Plain API, and I've been successful in all aspects of manipulating work items, build definitions, and source control except for one: adding comments to work items.
Here is the function in question:
def addCommentToWorkItem(String workItemId, String commentText, monitor=null) {
IContributor currentLoggedInContributor = repo.loggedInContributor();
IWorkItemClient wcl = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
IWorkItemWorkingCopyManager wcManager = wcl.getWorkItemWorkingCopyManager();
IWorkItem wi = (IWorkItem) wcl.findWorkItemById(Integer.parseInt(workItemId), IWorkItem.FULL_PROFILE, monitor);
wcManager.connect(wi, IWorkItem.FULL_PROFILE, monitor);
WorkItemWorkingCopy wiCopy = wcManager.getWorkingCopy(wi);
wi = wiCopy.getWorkItem();
// If the text contains links, add <a href="link">link text</a> in the text and use XMLString.createFromXMLText
// IComment comment = wi.getComments().createComment(currentLoggedInContributor, XMLString.createFromXMLText("Testing comment at " + System.currentTimeMillis() + "<a href=\"https://jazz.net\">jazz.net</a>"));
IComment comment = wi.getComments().createComment(currentLoggedInContributor, XMLString.createFromXMLText(commentText));
wi.getComments().append(comment);
wiCopy.save(monitor);
wcManager.disconnect(wi);
}
But even if I append comments to a working item copy and save that working item copy, I don't see any comments added to the work item. Am I missing something here?
One answer
You should use a workitem operation
The code here https://rsjazz.wordpress.com/2013/07/12/work-item-command-line-client-to-add-a-comment/ used to work.