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.
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
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
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
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.
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.
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:
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);
}
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!
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!
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!
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!
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
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