How to get the list of required attributes that needs to be setted by creating a new work item RTC Java API?
Hello,
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
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
You can find it in the work item common (and server)
IWorkItemCommon.findRequiredAttributes(workItem, workflowAction, monitor)
You can also find the read only attributes there.
IWorkItemCommon.findRequiredAttributes(workItem, workflowAction, monitor)
You can also find the read only attributes there.
Comments
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.
Adding a snippet (plain java api)
(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 + "<=");
}