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

How to add a Comment using the RTC API.

I would like the java code for adding a comment to an RTC work item.

0 votes

Comments

 Is it supposed to be a question?

 Is that supposed to be an answer ;)

If you don't have anything useful to say then don't say anything. 
The full code above may be useful to someone who is in a hurry, if not to you, bud.

Taigo's comment is valid for several reasons:
- We discourage posting answers to questions that nobody has asked.   There are 45,000 questions in the forum.   If nobody has asked the question, probably nobody is interested in the answer (at least, not yet).
- In this case, this question has been asked ( https://jazz.net/forum/questions/25483/add-comment-to-work-item-using-api ), and this would be a good answer, but it is much more useful to post this as an answer to that question, instead of posting it as a duplicate question that users have to then browse through to find which one has a good answer.
- And if you decide to ignore the first two comments, at the very least you should post your answer as an "answer" to your question, and not embed the answer in the question field, so that the question shows up as being answered.   I'll go ahead and make that edit.



One answer

Permanent link
(Answer from Simon Starkie)
This is working for us:
package com.ibm.js.team.workitem.plainjava.example;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;

import com.ibm.team.filesystem.client.internal.rest.util.LoginUtil.LoginHandler;
import com.ibm.team.repository.client.ITeamRepository;
import com.ibm.team.repository.client.TeamPlatform;
import com.ibm.team.repository.common.IContributor;
import com.ibm.team.repository.common.ItemNotFoundException;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.workitem.common.IWorkItemCommon;
import com.ibm.team.workitem.common.model.IWorkItem;

public class WorkItemAddCommentTest {

public static void main(String[] args) {
boolean result;
TeamPlatform.startup();
try {
result = run(args);
} catch (TeamRepositoryException x) {
x.printStackTrace();
result = false;
} finally {
TeamPlatform.shutdown();
}

if (!result)
System.exit(1);
}

private static boolean run(String[] args) throws TeamRepositoryException {
boolean result = false;
if (args.length  != 6) {
System.out
.println("Usage: AddComment      []");
return result;
}

String repositoryURI = args[0];
String userId = args[1];
String password = args[2];
String idString = args[3];
String commentText = args[4];
String commenterID = null;
if (args.length == 6) {
commenterID = args[5];
}

IProgressMonitor monitor = new NullProgressMonitor();
ITeamRepository teamRepository = TeamPlatform
.getTeamRepositoryService().getTeamRepository(repositoryURI);
teamRepository.registerLoginHandler(new LoginHandler(userId, password));
teamRepository.login(monitor);

IContributor commentUser = null;
if (null != commenterID) {
try {
commentUser = teamRepository.contributorManager().fetchContributorByUserId(
commenterID, monitor);
} catch (ItemNotFoundException e) {
}
}
if (commentUser == null) {
commentUser = teamRepository.loggedInContributor();
}

// Use IWorkItemClient or IWorkItemCommon
IWorkItemCommon workItemCommon = (IWorkItemCommon) teamRepository
.getClientLibrary(IWorkItemCommon.class);
int id = new Integer(idString).intValue();
IWorkItem workItem = workItemCommon.findWorkItemById(id,
IWorkItem.SMALL_PROFILE, monitor);

if(null!=workItem){
WorkItemAddComment operation = new WorkItemAddComment(commentUser,
commentText);
operation.run(workItem, monitor);
System.out.println("Modified item " + workItem.getId() + ".");
result=true;

} else{
System.out.println("Canfind work Item " + idString + ".");
}
teamRepository.logout();
return result;
}
}

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,954

Question asked: Jun 02 '15, 12:16 p.m.

Question was seen: 4,017 times

Last updated: Jun 05 '15, 2:24 a.m.

Confirmation Cancel Confirm