cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How to programmatically delete unique templates

Highlighted
Newbie

How to programmatically delete unique templates

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

1 REPLY 1

Re: How to programmatically delete unique templates

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