It's all about the answers!

Ask a question

How to import workitem Templates (xml) into project area via JAVA API?

Philipp Selle (157) | asked Nov 17 '15, 8:37 a.m.
edited Nov 17 '15, 8:39 a.m.
Hello everyone,

I need to import a workitem template into my project area. Has anyone experiences with that?
I've already checked the WorkItemTemplateImportWizard class, which has following code (some modifications are made):

Map<String, IWorkItemTemplateHandle> existingTemplates= new HashMap<String, IWorkItemTemplateHandle>();
List<WorkItemTemplate> newTemplates= new ArrayList<WorkItemTemplate>();
IWorkItemTemplateClient templateClient= (IWorkItemTemplateClient)repo.getClientLibrary(IWorkItemTemplateClient.class);
IWorkItemClient itemClient= (IWorkItemClient)repo.getClientLibrary(IWorkItemClient.class);
projectArea = (IProjectArea) projectArea.getWorkingCopy();
XMLTemplateParser parser= new XMLTemplateParser(projectArea, itemClient);
String xmlContent= ""<?xml version=\....."
(I wrote a simple XML into the string for testing, later on the content comes from an external xml file)
List<IWorkItemTemplateHandle> templateHandles= templateClient.getTemplateHandles(projectArea, monitor);
        for (IWorkItemTemplateHandle cur : templateHandles) {
            existingTemplates.put(cur.getName(), cur);       
IProcessItemService processItemService = (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);, monitor);

I already checked the value of the variables newTemplates and existingTemplates. "newTemplates" has all attributes of my imported template and "existingTemplates" has all attributes of my current templates. So I'm confident to get it done with your help!

After running the code, there is no error and unfortunately no new template either. It seems that I do not save the right part(?)
Any tips or hints?

Thank you in advance!

One answer

permanent link
Philipp Selle (157) | answered Nov 17 '15, 9:24 a.m.
I tried following code and it works:

IWorkItemTemplate template = (WorkItemTemplate)parser.parseTemplate(xmlContent);
templateClient.importTemplate(template, false, monitor);

Your answer

Register or to post your answer.