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

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());

}
}
}


0 votes



2 answers

Permanent link

 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

1 vote

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!


Permanent link

 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

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,937
× 7,495
× 1,325

Question asked: Oct 07 '22, 12:45 a.m.

Question was seen: 1,267 times

Last updated: Oct 11 '22, 6:57 a.m.

Related questions
Confirmation Cancel Confirm