How to import workitem Templates (xml) into project area via JAVA API?
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) newTemplates.add((WorkItemTemplate)parser.parseTemplate(xmlContent)); List<IWorkItemTemplateHandle> templateHandles= templateClient.getTemplateHandles(projectArea, monitor); for (IWorkItemTemplateHandle cur : templateHandles) { existingTemplates.put(cur.getName(), cur); } IProcessItemService processItemService = (IProcessItemService) repo.getClientLibrary(IProcessItemService.class); processItemService.save(projectArea, 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! Philipp |
One answer
I tried following code and it works:
IWorkItemTemplate template = (WorkItemTemplate)parser.parseTemplate(xmlContent); templateClient.importTemplate(template, false, monitor); |
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.