It's all about the answers!

Ask a question

Adding comments while creating workitem using java APi


Sudipto Sarkar (631243) | asked Jul 31 '15, 6:19 a.m.
edited Jul 31 '15, 6:28 a.m. by Ralph Schoon (63.1k33645)
Hi Everyone,

 I am creating a workitem using plain Java Api. I want to add some comments while creating. Please help me. I got solution to modify the existing workitem and then add comment,  but my use case id to add a comment while creating workitem.

Thanks,
Sud

Accepted answer


permanent link
Ralph Schoon (63.1k33645) | answered Jul 31 '15, 6:27 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
See https://rsjazz.wordpress.com/2013/07/12/work-item-command-line-client-to-add-a-comment/

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

Sudipto Sarkar selected this answer as the correct answer

Comments
Sudipto Sarkar commented Jul 31 '15, 7:11 a.m.

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


Sudipto Sarkar commented Jul 31 '15, 7:17 a.m.

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



permanent link
Sudipto Sarkar (631243) | answered Jul 31 '15, 7:18 a.m.
IComments comments = workItem.getComments();
            IComment newComment = comments.createComment(repo.loggedInContributor(),
                    XMLString.createFromPlainText("New Comment"));
            comments.append(newComment);

Comments
Ralph Schoon commented Jul 31 '15, 7:45 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.

Your answer


Register or 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.