How I add new comment for WorkItem using Server Side Plugin
I need a some help. I have an advisor plugin in RTC. I want to add new comment my source workitem.
My code:
IComments comments = sourceworkItem.getComments();But i get this error:
IContributorHandle creator = contributorService.fetchContributorByUserId("JAZZDEVADM");
String commentString = "content content some content";
XMLString content = XMLString.createFromPlainText(commentString);
IComment comment = (IComment) comments.createComment(creator, content);
comments.append(comment);
Validation errors for item: type = WorkItem, itemId = [UUID _L2jbAIaJEeSkQJKbbjlvNg]Why this happen? How i can set creationDate?
Required property must not be null: internalComments.creationDate
Validation errors for item: type = WorkItem, itemId = [UUID _L2jbAIaJEeSkQJKbbjlvNg]
Required property must not be null: internalComments.creationDate
Accepted answer
Hi all,
I'd like to share how I did!
The comments aren't a attribute, but a collection.
IComments comments = workItem.getComments();
Comment newComment = (Comment) comments
.createComment(
workItem.getCreator(),
XMLString.createFromPlainText("write your comment here"));
//You have to set a creation date, required.
Timestamp now = new Timestamp(System.currentTimeMillis());
newComment.setCreationDate(now);
comments.append(newComment);
//if you want to see your comments list.
IComment[] contents = comments.getContents();
for (IComment iComment : contents) {
System.out.println(iComment.getHTMLContent());
}
Hope I can help anybody else, if you like it let a thumbs up!
2 other answers
Are you creating a workitem that same advisor? The workitem must have a "creation date".
Try:
sourceworkItem.setCreationDate(<Timestamp>);
PS: Insert the code above before the comment creation.