It's all about the answers!

Ask a question

Attempting to add comment to work item - comments are not added


0
1
Peter Carenza (132) | asked May 10 '21, 3:29 p.m.

 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



permanent link
Ralph Schoon (62.0k33643) | answered May 11 '21, 2:21 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 

You should use a workitem operation

Your answer


Register or to post your answer.