It's all about the answers!

Ask a question

How to add custom attribute to Work item type definition by using Plain Java API


Tadahiro Hara (927) | asked Nov 05 '23, 11:28 p.m.

Please kindly let me know how to add a custom attribute to a Work item type by using Plain Java API.

I have added some custom attributes to a project area by using the following code.

IWorkItemClient workItemClient = (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);

IProcessItemService processService = (IProcessItemService) teamRepository.getClientLibrary(IProcessItemService.class);
URI uri = URI.create(projectName.replaceAll(" ", "%20"));
IProjectArea projectArea = (IProjectArea) processService.findProcessArea(uri, null, monitor);
if (projectArea == null) {
throw new InvalidArgumentException("Project area not found.");
}
IProjectArea projectAreaCopy = (IProjectArea) processService.getMutableCopy(projectArea);

        // Specify the work item type ID and the custom attribute details
        String workItemTypeId = WorkItemTypes.TASK;
        String customAttributeId = "customattribute2";
        String customAttributeDisplayName = "CustomAttribute2";
        String customAttributeType = AttributeTypes.SMALL_STRING; 
        
        IAttribute customAttribute = workItemClient.createAttribute(projectAreaCopy, customAttributeId, customAttributeType,customAttributeDisplayName, monitor);
        
However, I can not find how to add these custom attributes to a Work item type.
com.ibm.team.workitem.common.model.IWorkItemType does not have any feature to update work item type definition.

Accepted answer


permanent link
Ralph Schoon (63.5k33646) | answered Nov 06 '23, 3:20 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 As far as I can tell, there is no dedicated API to add a custom attribute to the process.  createAttribute creates an attribute on a specific work item. It does not store this information in the process XML. You can debug the rich client platform implementation of Eclipse, how that creates custom attributes, but you will likely not find public API. 

Tadahiro Hara selected this answer as the correct answer

Your answer


Register or 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.