It's all about the answers!

Ask a question

How to save changes made programmatically on a workitem


Ananya Joisa (4552124) | asked Sep 25 '12, 9:34 a.m.
Hi,

I am trying to programmatically set the description of a workitem. This is what I am trying to do :

String desc = "Hello";
XMLString description = XMLString.createFromPlainText(desc);
newState.setHTMLDescription(description);

While debugging I see that the 'description' value of newState is set to 'Hello'. But the changes are not seen in the Work item UI. Should I be saving the changes or something  similar? Please help!

Thanks.



8 answers



permanent link
Dinesh Kumar (4.0k413) | answered Sep 25 '12, 10:25 a.m.
JAZZ DEVELOPER
edited Sep 25 '12, 10:26 a.m.
you need a handle to the Working copy and perform a .save on it.

below is something i use to add comments

IWorkItemClient workItemClient = (IWorkItemClient)mTeamRepository.getClientLibrary(IWorkItemClient.class); 
        IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager(); 

        try {
           
            wcm.connect(resWI, IWorkItem.FULL_PROFILE, mMonitor);
           
        } catch (TeamRepositoryException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.exit(0);
        }
       
        WorkItemWorkingCopy workingCopy = wcm.getWorkingCopy(resWI);

        IWorkItem workItem= workingCopy.getWorkItem();
        IComment comment = workItem.getComments().createComment(resWI.getOwner(), XMLString.createFromPlainText(mailInfo));
        workItem.getComments().append(comment);

        workingCopy.save(null);



hope it helps

permanent link
Ananya Joisa (4552124) | answered Sep 26 '12, 4:40 a.m.
Dinesh, thanks for replying.

I changed my code according to your comment above.

My code looks like this :

       IWorkItemClient workItemClient = (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);
        IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager();
        IProgressMonitor newMonitor = new NullProgressMonitor();
        wcm.connect(newState, IWorkItem.FULL_PROFILE, newMonitor);
        WorkItemWorkingCopy workingCopy = wcm.getWorkingCopy(newState);

        IWorkItem workItem= workingCopy.getWorkItem();
        String desc = "Hello";
        XMLString description = XMLString.createFromPlainText(desc);
        workItem.setHTMLDescription(description);

        workingCopy.save(newMonitor);

I was debugging and I saw that "Hello" is being stored in the description field of workItem. While I come to the line "workingCopy.save(newMonitor); ", the debugger pauses for pretty long time and I see the error:

java.sql.SQLException: A lock could not be obtained within the time requested
And "Hello" is not seen in the descriotion field of the workItem UI.

Please guide!

Thanks.

permanent link
Ralph Schoon (56.5k23642) | answered Sep 26 '12, 6:13 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Sep 26 '12, 6:13 a.m.
Hi, you can also take the approach using a WorkItemOperation to modify the work item. See http://rsjazz.wordpress.com/2012/08/01/uploading-attachments-to-work-items/.

I am not sure why you get the SQL error. I have never seen anything like that. My code using a workingcopy looks like:

  int id = new Integer(idString).intValue();
IWorkItem workItem = workItemClient.findWorkItemById(id, IWorkItem.SMALL_PROFILE, null);
IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager(); wcm.connect(workItem, IWorkItem.FULL_PROFILE, null);
try {
  WorkItemWorkingCopy wc = wcm.getWorkingCopy(workItem);
  wc.getWorkItem().setHTMLSummary(XMLString.createFromPlainText(summary));  

  IDetailedStatus s = wc.save(null);
  if (!s.isOK()) {
     throw new TeamRepositoryException("Error saving work item", s.getException());
  }
}
finally {
wcm.disconnect(workItem);
}



permanent link
Ralph Schoon (56.5k23642) | answered Sep 26 '12, 6:15 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
On a second thought, it appears you are trying to manipulate in a server extension. See http://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/ as an example.

permanent link
Ananya Joisa (4552124) | answered Sep 26 '12, 6:23 a.m.
Thanks Ralph for replying.

I am actually trying to set the output of build.xml (from the build definition) in the description field of the work item.

And in your first comment, idString is the id of the workitem right?
Also, are you getting 'workItemClient' from
IWorkItemClient workItemClient = (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);
?

Thank you!

permanent link
Ralph Schoon (56.5k23642) | answered Sep 26 '12, 7:00 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi Ananya, yes and yes.

permanent link
Ananya Joisa (4552124) | answered Sep 27 '12, 1:28 a.m.
Ralph,

I am following the document that you pointed out sometime back and now I am extending it as per team's requirement : https://jazz.net/library/content/articles/rtc/3.0.1/extensions-workshop/RTC301ExtPoT.pdf

I have not deployed the code yet since I am still making changes. Hence I have 2 client's open. One runs the build and the other for debugging. Since 2 clients are accessing the work item, I am getting the 'lock not obtained' issue that I was talking about in my second comment.

Is there a way to get through this issue.

Thanks for your help!

permanent link
Ananya Joisa (4552124) | answered Oct 12 '12, 8:01 a.m.
Hi,

What I am trying to do is, I want to set the output of the scripts that I run through the above mentioned perl script in the description field of the workitem.
I have not deployed my code yet and hence I have 2 RTC clients open as seen in the document, the original client(for debugging) and TestProject1(for running builds/workitems).
When I created the workingCopy of the workItem, set the description and tried to save the workingCopy, I get a "Lock could not be obtained" error. I assumed since there are 2 clients are accessing the workItem, the lock issue is appearing.
Is there a way to get through this or an alternative method?

Below is the code I used to set the description and save the workingCopy

IWorkItemClient workItemClient = (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);
IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager();
IProgressMonitor newMonitor = new NullProgressMonitor();
wcm.connect(newState, IWorkItem.FULL_PROFILE, newMonitor);
WorkItemWorkingCopy workingCopy = wcm.getWorkingCopy(newState);

IWorkItem workItem= workingCopy.getWorkItem();
String desc = "Hello";
XMLString description = XMLString.createFromPlainText(desc);
workItem.setHTMLDescription(description);

workingCopy.save(newMonitor);
wcm.disconnect(workItem);

I was debugging and I saw that "Hello" is being stored in the description field of workItem. While I come to the line "workingCopy.save(newMonitor); ", the debugger pauses for pretty long time and I see the error:

java.sql.SQLException: A lock could not be obtained within the time requested

FYI, I have followed the document https://jazz.net/library/content/articles/rtc/3.0.1/extensions-workshop/RTC301ExtPoT.pdf for extension and deploying.

Thanks,
Ananya

Your answer


Register or to post your answer.