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

Adding comments while creating workitem using java APi

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

1 vote


Accepted answer

Permanent link
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

1 vote

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

Permanent link
IComments comments = workItem.getComments();
            IComment newComment = comments.createComment(repo.loggedInContributor(),
                    XMLString.createFromPlainText("New Comment"));
            comments.append(newComment);

0 votes

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.

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

Question asked: Jul 31 '15, 6:19 a.m.

Question was seen: 3,765 times

Last updated: Jul 31 '15, 7:45 a.m.

Confirmation Cancel Confirm