Adding comments while creating workitem using java APi
Accepted answer
This is no different to modifying the work item. You do it in a WorkItemOperation
private static class WorkItemInitialization extends WorkItemOperation {
private String fSummary;
private ICategoryHandle fCategory;
public WorkItemInitialization(String summary, ICategoryHandle category) {
super("Initializing Work Item");
fSummary = summary;
fCategory = category;
}
@Override
protected void execute(WorkItemWorkingCopy workingCopy,
IProgressMonitor monitor) throws TeamRepositoryException {
IWorkItem workItem = workingCopy.getWorkItem();
workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary));
workItem.setHTMLDescription(XMLString.createFromPlainText(fSummary));
workItem.setCategory(fCategory);
List tags = workItem.getTags2();
tags.add("NewTag");
workItem.setTags2(tags);
}
}
You add the comment in the execute section. You run it this way.
WorkItemInitialization operation = new WorkItemInitialization("Test", category);
IWorkItemHandle handle = operation.run(workItemType, monitor);
Comments
Hi,
I tried to follow above code,but the comment is added to "Tags" field in the created workitem.
Below is my code.
IWorkItem workItem = wc.getWorkItem();
workItem.setCategory(category);
workItem.setTarget(fetchIterations(pa, repo, monitor, count, sheet));
workItem.setOwner(input.getAlmOwner(pa, count, sheet, repo));
workItem.setTags("CS-CRM");
List<String> tags = workItem.getTags2();
tags.add("New Comment");
workItem.setTags2(tags);
https://rsjazz.wordpress.com/2013/07/12/work-item-command-line-client-to-add-a-comment/
This helped me.
IComments comments = workItem.getComments();
IComment newComment = comments.createComment(repo.loggedInContributor(),
XMLString.createFromPlainText("New Comment"));
comments.append(newComment);
I am able to add comments.
Thanks!
One other answer
IComment newComment = comments.createComment(repo.loggedInContributor(),
XMLString.createFromPlainText("New Comment"));
comments.append(newComment);
Comments
As described in https://rsjazz.wordpress.com/2013/07/12/work-item-command-line-client-to-add-a-comment/
Please accept the answer so that I don't have to.