It's all about the answers!

Ask a question

Update RTC Work Item programmatically using client side APIs


Vaibhav S (106130) | asked Oct 07 '22, 12:45 a.m.

 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



permanent link
Ralph Schoon (62.0k33643) | answered Oct 07 '22, 7:54 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 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
Vaibhav S commented Oct 10 '22, 6:46 a.m.

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!


permanent link
Ralph Schoon (62.0k33643) | answered Oct 11 '22, 3:04 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Oct 11 '22, 6:57 a.m.

 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);
operation.run("New Summary", monitor);
Also see https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation

Your answer


Register or to post your answer.