How to get the list of required attributes that needs to be setted by creating a new work item RTC Java API?
In my Java client application, I need to create a lot of new Work Items. I have two repositories and several projects area on them, and for each project there are the different fields (attributes) that are required to be set by creating new item. So, here is my question from the topic: is there a way to get list of required attributes from specified project?
Thank you,
Kamil
Accepted answer
IWorkItemCommon.findRequiredAttributes(workItem, workflowAction, monitor)
You can also find the read only attributes there.
Comments
Thank you for your answer! So, can I get the instance of IWorkItemCommon from server using ITeamRepository.getClientLibrary(Class arg)? Could you also tell me, what is the workflowAction? Maybe this question are silly, but I'm only beginning developing in that API :)
Thanks in advance!
Kamil
Yes, in the Client API you get the client library. In the server API you get the IWorkItemServer with an analog call.
Like in https://rsjazz.wordpress.com/2016/07/15/build-on-state-change-work-item-save-participant/ you use com.ibm.team.repository.service.AbstractService as superclass and then you use getService()
2 other answers
hi kamil,
i dont know, how to get list of required attributes but you can try to read this topic:
https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/
its maybe help you...
other way: i have 2 ideas about this topic
1- u can handle error in your java api and set the attribute one by one...
for example:
error message: you can set the summary
if it is set the summary
i think it is bad idea :)
2- u can list the required fields manuel for each project area (just 1 times) and use this list in your code...
if required attributes changing in time maybe you can try to save the list as xml or config file and read in your java code easyly.
(IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);
String workItemTypeId = ....;
IWorkItemType workItemType = workItemClient.findWorkItemType(projectAreaHandle, workItemTypeId, progressMonitor);
IWorkItemWorkingCopyManager workItemWorkingCopyManager = workItemClient.getWorkItemWorkingCopyManager();
workItemHandle = workItemWorkingCopyManager.connectNew(workItemType, progressMonitor);
WorkItemWorkingCopy workItemWorkingCopy = workItemWorkingCopyManager.getWorkingCopy(workItemHandle);
IWorkItem workItem = workItemWorkingCopy.getWorkItem();
Collection<String> requiredAttributes = workItemClient.findRequiredAttributes(workItem, null, progressMonitor);
for (String requiredAttribute : requiredAttributes) {
log.trace("requiredAttribute =>" + requiredAttribute + "<=");
}