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

appending Comments during an initial programmatic create

I am programmatically creating work items and I am having issues doing comments.  The code does this:

//get a "working copy" of an empty work item
final IWorkItemType workItemType = workItemClient.findWorkItemType (projArea, "defect", null);
final IWorkItemHandle handle = workItemClient.getWorkItemWorkingCopyManager().connectNew (workItemType, null);
final WorkItemWorkingCopy workingCopy = workItemClient.getWorkItemWorkingCopyManager ().getWorkingCopy (handle);
final IWorkItem workItem = workingCopy.getWorkItem ();

//fill in all the values
.
//Description
XMLString description = XMLString.createFromPlainText(descriptionText);
workItem.setHTMLDescription (description);           

.
//add the comments
IComments srcComments = workItem.getComments();
XMLString content = XMLString.createFromPlainText(contentString);
IComment ic = srcComments.createComment(creator , content);
srcComments.append(ic);
//workItem.setValue(comment,srcComments);

//save to create it
final IDetailedStatus status = workingCopy.save (null);

Now, I was trying the setValue() at the end but that gave a classCastException, so I removed it.  My code runs and the description shows up in the new work item, but no comments.  The description uses setHTMLDescription() but I didn't find a "setComments() or setHTMLComments().

Has anyone done this?  Can you send a snippet or tell me what I am doing wrong??

Thanks in advance,
susan

1

1 vote


Accepted answer

Permanent link
Hi Susan,
the code below works for us:
ITeamRepository repo = ...
WorkItemWorkingCopy workingCopy = ...
IWorkItem wiFreshCopy = workingCopy.getWorkItem();
IComments comments = wiFreshCopy.getComments();
String msg = ...
IComment comment = comments.createComment(repo.loggedInContributor(), XMLString.createFromPlainText(msg)); 
comments.append(comment);
workingCopy.save(null);

Cheers.
Ralph Schoon selected this answer as the correct answer

1 vote

Comments

Okay, so very interesting .. .it seems like the content of my comment is causing the issue but I am not getting an error (it just ignores). For example, if my "msg" variable is: String msg = "my comment is here"; then it works. if I change it to: String msg = "my comment line 1" + "\n" + "my comment line 2";

then my comment is ignored AND I don't get an error.

Any ideas? I want to be able to have multiple lines, and I can do that using the eclipse client, so I assumed I could do this programmatically. Using the "\n" works programmatically in the Description.

Weird... We use multi-line comments, too. Notice that we use: XMLString.createFromPlainText(msg);


One other answer

Permanent link
Hi,

try this method.

WorkItem.getComments.append(IComment);

This IComment parameter you can create by WorkItem.getComment.CreateComment(); method.

Regards
Muthukumar.C

1 vote

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

Question asked: Jun 27 '12, 1:01 a.m.

Question was seen: 4,717 times

Last updated: Jun 27 '12, 11:31 a.m.

Confirmation Cancel Confirm