Update RTC Work Item programmatically using client side APIs
Hi ,
i need to Update RTC Work Item programmatically using client side APIs. I tried using set methods of Working Copy and then saving it but it results in creation of a new Work Item instead of updating the existing one.
Please let me know what edit can be used for Update. Thanks!
teamRepositoryTemp = TeamPlatform.getTeamRepositoryService()
.getTeamRepository(mapMbseWorkItemAttributesChild.get("repositoryURI"));
teamRepositoryTemp.registerLoginHandler(new LoginHandler(mapMbseWorkItemAttributesChild.get("userId"),
mapMbseWorkItemAttributesChild.get("password")));
teamRepositoryTemp.login(null);
IProcessClientService processClient = (IProcessClientService) teamRepository
.getClientLibrary(IProcessClientService.class);
IAuditableClient auditableClient = (IAuditableClient) teamRepository
.getClientLibrary(IAuditableClient.class);
IWorkItemClient workItemClient = (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);
IWorkItemClient workItemClientTemp = (IWorkItemClient) teamRepositoryTemp
.getClientLibrary(IWorkItemClient.class);
URI uri = URI.create(mapMbseWorkItemAttributesChild.get("projectAreaName").replaceAll(" ", "%20"));
IProjectArea projectArea = (IProjectArea) processClient.findProcessArea(uri, null, null);
if (mapMbseWorkItemAttributesChild.get("projectAreaName") == null) {
// System.out.println("Project area not found.");
return 0;
}
Query to find the Work item
IQueryClient queryClient = (IQueryClient) teamRepository.getClientLibrary(IQueryClient.class);
IProjectAreaHandle iProjectAreaHandle = (IProjectAreaHandle) projectArea.getItemHandle();
IQueryableAttribute attribute = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE)
.findAttribute(iProjectAreaHandle, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, null);
Expression expression = new AttributeExpression(attribute, AttributeOperation.EQUALS, iProjectAreaHandle);
IQueryResult<IResolvedResult<IWorkItem>> results = queryClient.getResolvedExpressionResults(projectArea,
expression, IWorkItem.FULL_PROFILE);
IAuditableCommon auditableCommon = (IAuditableCommon) teamRepository
.getClientLibrary(IAuditableCommon.class);
while (results.hasNext(null))
{
String displayValue = null;
IResolvedResult<IWorkItem> result = (IResolvedResult<IWorkItem>) results.next(null);
workItem = auditableCommon.resolveAuditable((IAuditableHandle) result.getItem(),
IWorkItem.ID_PROFILE, null);
String workItems = workItem.getWorkItemType();
ICategoryHandle workItemCategory = workItem.getCategory();
ICategory categoryName = (ICategory) teamRepository.itemManager().fetchCompleteItem(workItemCategory,
IItemManager.DEFAULT, new NullProgressMonitor());
Set the value here
wc.getWorkItem().setValue(summaryVFNameAttribute, mapMbseWorkItemAttributesParent.get("VF Number"));
Save the changes
IDetailedStatus status = wc.save(new NullProgressMonitor());
if (status.getCode() != org.eclipse.core.runtime.IStatus.OK) {
System.out.println("Error: " + status.getDetails());
}
}
}
2 answers
Do not use a workingcopy manager. Use a workitem operation see https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ section Alternative to Create and Modify Work Items also see https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation
Comments
Hi Ralph,
thanks for the response. Instead of using Handle is used WorkItem client,
// IWorkItemClient service = (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);
// IWorkItemHandle handle = service.getWorkItemWorkingCopyManager().connectNew(workItemType,
// new NullProgressMonitor());
IWorkItemWorkingCopyManager copyManager = workItemClient.getWorkItemWorkingCopyManager();
copyManager.connect(workItem, IWorkItem.FULL_PROFILE, null);
WorkItemWorkingCopy wc = copyManager.getWorkingCopy(workItem);
// workItem = wc.getWorkItem();
Thanks!
As already mentioned, I would suggest to NOT use the WorkingCopyManager. Use an WorkitemOperation instead. The code looks like:
private static class WorkItemSummaryModification extends WorkItemOperation {private String fSummary; public WorkItemSummaryModification(String newSummary) { super("Modifying Work Item", IWorkItem.FULL_PROFILE); fSummary = newSummary; } @Override protected void execute(WorkItemWorkingCopy workingCopy, IProgressMonitor monitor) throws TeamRepositoryException { IWorkItem workItem = workingCopy.getWorkItem(); workItem.setHTMLSummary(XMLString.createFromPlainText(fSummary)); } }
The code is called this way:
WorkItemSummaryModification operation= new WorkItemSummaryModification(workItem);Also see https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation
operation.run("New Summary", monitor);