Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Hello!
Does anyone know how to delete templates programatically?
Reason is to create a customized loader that can handle the problem when a non iterable template (such as task templates or container templates) need to be refreshed.
Today we get a silly exception that the template is already in the system and cannot be replaced.
Any help is appreciated!
Thanks and best regards,
Peter
Found out how to retrieve and delete task form templates before loading them:
First you need to find the template:
QuerySpec qs = new QuerySpec(TaskFormTemplate.class); | |
qs.addClassList(TaskFormTemplate.class, true); | |
qs.appendWhere(new SearchCondition(TaskFormTemplate.class, TaskFormTemplate.NAME, SearchCondition.EQUAL, "name", false), new int[]{0}); |
Then below code did the delete:
DeleteHelper.manager.markForDelete(taskformtemplate.getMaster()); | |
StringBuffer stringbuffer = new StringBuffer(""); | |
if (taskformtemplate.getTypeFormat().equalsIgnoreCase("jsp")) { | |
stringbuffer = getFilePathForJSPTemplates(); | |
} else { | |
stringbuffer = new StringBuffer((new StringBuilder()).append(CODEBASE).append(File.separator).append("netmarkets").append(File.separator).append("customtemplates").toString()); | |
} | |
stringbuffer.append((new StringBuilder()).append(File.separator).append(getTemplateURL(taskformtemplate.getTaskType(), taskformtemplate.getContainerReference(), taskformtemplate.getPboClass(), taskformtemplate.getTypeFormat(), taskformtemplate.getName())).toString()); | |
File file = new File(stringbuffer.toString()); |
file.delete(); |
I have left out some stuff but I think you can figure that out yourselves
Best regards,
Peter