If you look into the Email Form while setting an “Send Email” Action on a folder you would be wondering how we can add new email templates into the list of drop down “Use Template” as shown below -

MyImage

The only option without any customization is to add your templates into the folder : Repository > Data Dictionary > Email Templates > Notify Email Templates

How does this work?

Look for the bean ‘ac-email-templates’ in alfresco/WEB-INF/classes/alfresco/action-services-context.xml which has the definition as below -

The property searchPath is what restricts it from fetching templates from a single folder.

What we need to change?

Let’s bring in our changes so that we can have multiple folders to select the templates from. For this we will be overriding the bean as below -

The first change is converting the property searchPath from a String literal to a List.

1
private List<String> searchPath = Collections.emptyList();

Then update the getAllowableValuesImpl() method so that it parses each folder path to search for what files to be included in the dropdown.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
protected Map<String, String> getAllowableValuesImpl() {
    Map<String, String> result = new HashMap<String, String>(23);
    for(String path : searchPath){
        List<NodeRef> nodeRefs = searchService.selectNodes(repository.getRootHome(),path,null,this.namespaceService,false);
        NodeRef rootFolder = null;
        if (nodeRefs.size() == 0)
        {
            throw new AlfrescoRuntimeException("The path '" + searchPath + "' did not return any results.");
        }
        else
        {
            rootFolder = nodeRefs.get(0);
        }
        buildMap(result, rootFolder);
    }
    Map<String,String> sortedResult = sortByName(result);
    return sortedResult;
}

I have also added an extra method sortByName so that the values in the dropdown are displayed in sorted order by their name.

Checkout the code for FolderContentsParameterConstraint for a better understanding of how it works.

I made this whole project as 2 step -

  1. First is bootstrapping a template under a specified path. v1.0
  2. Make the templates available for selection under Email Action. v2.0

The source code for this project lives here