It's all about the answers!

Ask a question

Setting "Discussion" attribute of Work Item

Fatla 777 (263712) | asked May 13 '13, 8:46 a.m.
 I am trying to set the value of "Discussion" at work item pragmatically.

I managed to set the "Description" attribute but when I tried to set the Discussion I got null pointer exception :

                IWorkItemClient workItemClient= (IWorkItemClient)repository.getClientLibrary(IWorkItemClient.class);
 IWorkItemWorkingCopyManager manager= workItemClient.getWorkItemWorkingCopyManager();
 manager.connect(workItem, IWorkItem.SMALL_PROFILE, SysoutProgressMonitor.getMonitor());
 WorkItemWorkingCopy wc= manager.getWorkingCopy(workItem);
  IProgressMonitor monitor = SysoutProgressMonitor.getMonitor();
  IWorkItemClient service = (IWorkItemClient) repository.getClientLibrary(IWorkItemClient.class);

        IAttribute discussionAttribute = service.findAttribute(projectArea, "discussion", monitor);//Here I got  a null "discussionAttribute"?

   wc.getWorkItem().setValue(discussionAttribute, "New Value for Discussion");

Any ideas!

Accepted answer

permanent link
sam detweiler (12.5k6189201) | answered May 13 '13, 10:40 a.m.
yeh, its id is "internalComments".. don't know why it doesn't respond to Comments

see my sample dump all attributes code here , second post

Fatla 777 selected this answer as the correct answer

Fatla 777 commented May 13 '13, 11:04 a.m.

Thanks i got the comments attribute... um trying now to add a comment to it.

Fatla 777 commented May 13 '13, 12:45 p.m.

When I tried to set the new comment,everything goes right

However,when I open my work item to find the updates,nothing is added!

Fatla 777 commented May 13 '13, 12:46 p.m.

 IComments comments=workItem.getWorkItem().getComments();  

 IAttribute commentsAttr =  service.findAttribute(projectArea, "internalComments", monitor);  

Fatla 777 commented May 13 '13, 12:46 p.m. | edited May 13 '13, 1:12 p.m.
List commentList=new ArrayList();
 commentList.add(comments.getContents()[0]);//POC  commentList.add(comments.getContents()[0]); //POC
workItem.getWorkItem().setValue(commentsAttr, commentList); 

sam detweiler commented May 13 '13, 2:11 p.m.

and then.. you have to SAVE the workitem

I 'think' its like this in your sample p);

Fatla 777 commented May 13 '13, 2:34 p.m.

I already had this line ... but I think the issue in that line:

wc.getWorkItem().setValue(commentsAttr, commentList);

For some reason when I removed it ,it works :)
Merci Sam :) 

showing 5 of 6 show 1 more comments

4 other answers

permanent link
Fatla 777 (263712) | answered May 13 '13, 2:42 p.m.
This is the final resolution and it works :)
Thanks to Sam.

IWorkItemClient workItemClient= (IWorkItemClient)repository.getClientLibrary(IWorkItemClient.class);
IWorkItemWorkingCopyManager manager= workItemClient.getWorkItemWorkingCopyManager();
manager.connect(workItem, IWorkItem.SMALL_PROFILE, SysoutProgressMonitor.getMonitor());
WorkItemWorkingCopy wc= manager.getWorkingCopy(workItem);
IAttribute commentsAttr =  findAttribute(repository, projectArea, "internalComments");
IComments comments= wc.getWorkItem().getComments();
IComment comment= comments.createComment( repository.loggedInContributor(),
XMLString.createFromPlainText( "Aloo from Mars"));


permanent link
sam detweiler (12.5k6189201) | answered May 13 '13, 9:11 a.m.
for the 'how', download the java doc

the xml - I edited the process config, and found the comments attribute
there is no 'discussion' attribute.. (at least not in the out of the box objects) if it is a custom object, then you would have to use the 'id' value

Fatla 777 commented May 13 '13, 9:40 a.m.

I tried to fetch the comments by this way but I received a null object:!

IAttribute attribute = service.findAttribute(projectArea, "comments", monitor); 

Fatla 777 commented May 13 '13, 9:49 a.m.

I found this at my config:

<section id="">
       <presentation id="" kind="">
           <property key="hideIfCreation" value="true"/>

How can I set it programatically! 

Fatla 777 commented May 13 '13, 10:16 a.m.

I tried the following but I still get null !

 Attribute commentAttribute= service.findAttribute(projectArea, "", monitor);

permanent link
Fatla 777 (263712) | answered May 13 '13, 8:58 a.m.
edited May 13 '13, 9:06 a.m.
Being a newbie to RTC-API:
-How did you get this xml definition!
-I noticed that "Disccusion" has attributedefinition  .. so it is an attribute,isn't it
-How do I add a comment to its list!

Thanks Sam.

permanent link
sam detweiler (12.5k6189201) | answered May 13 '13, 8:52 a.m.
edited May 13 '13, 8:54 a.m.
discussion is not an attribute

the field is called comments

<attributeDefinition id="" name="Comments" type="comments"/>

it is an array (IComments) of comment objects. (IComment)

Your answer

Register or to post your answer.