It's all about the answers!

Ask a question

How I add new comment for WorkItem using Server Side Plugin

Hakki Bozkurt (1631228) | asked Nov 25 '15, 9:35 a.m.
 Hi all,

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(); 
IContributorHandle creator = contributorService.fetchContributorByUserId("JAZZDEVADM");
String commentString = "content content some content";
XMLString content = XMLString.createFromPlainText(commentString);
IComment comment = (IComment) comments.createComment(creator, content);
But i get this error: 
Error running operation 'Saving Work Item'
Validation errors for item: type = WorkItem, itemId = [UUID _L2jbAIaJEeSkQJKbbjlvNg]
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
Why this happen? How i can set creationDate? 

Accepted answer

permanent link
Peterson dos Santos (3928) | answered Oct 29 '23, 7:57 p.m.
edited Oct 29 '23, 8:06 p.m.

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
                             XMLString.createFromPlainText("write your comment here"));               

                   //You have to set a creation date, required.
                   Timestamp now = new Timestamp(System.currentTimeMillis());                    

                   //if you want to see your comments list.
                   IComment[] contents = comments.getContents();
                   for (IComment iComment : contents) {
Hope I can help anybody else, if you like it let a thumbs up!                   

Ralph Schoon selected this answer as the correct answer

2 other answers

permanent link
Pietro Bottino (35714) | answered Nov 25 '15, 1:24 p.m.
edited Nov 25 '15, 1:28 p.m.
Hello Hakki.

Are you creating a workitem that same advisor? The workitem must have a "creation date".


PS: Insert the code above before the comment creation.

Hakki Bozkurt commented Nov 25 '15, 1:48 p.m.

 Hello Pietro,

that creationdate not workitem creationdate, is comment creationdate. 
i am trying a new comment for existing workitem.

permanent link
Hakki Bozkurt (1631228) | answered Nov 25 '15, 1:51 p.m.
Hi all,

I found my answer, IComment setCreationDate not have setCreationDate so, i add cast "Comment". Its work.

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.