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

How to save changes made programmatically on a workitem

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.



0 votes



8 answers

Permanent link
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

0 votes


Permanent link
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.

0 votes


Permanent link
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);
}


0 votes


Permanent link
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.

0 votes


Permanent link
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!

0 votes


Permanent link
Hi Ananya, yes and yes.

0 votes


Permanent link
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!

0 votes


Permanent link
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

0 votes

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
× 10,927
× 369

Question asked: Sep 25 '12, 9:34 a.m.

Question was seen: 8,265 times

Last updated: Oct 12 '12, 8:01 a.m.

Confirmation Cancel Confirm