How to Send Multiple Document Links in an Automation Notification Email
Today we have a question from nicoespinoza who asks how to send selected multiple document links from an email notification template. When you use the Send E-Mail operation, it will send an email for each document given as input. So if you want to send only one email containing several document links, you can’t give all the selected documents as input. So the first thing to do here is put your selected documents in a context variable and give only one document as input to the Send E-Mail operation. Here’s how I did it:
I use the Fetch Document operation with the ‘/‘ parameter to have only one document as the input of the Send E-Mail operation. The ‘/‘ parameter identifies the root document of your repository.
The next question would be how to get the document links in the email template. A very simple email template displaying only the title and link to each document would look like this:
<#list selectedDocuments as document>
<a href="${baseUrl}nxdoc/${Session.getRepositoryName()}/${document.id}/${viewId}">${document.title}</a>
</#list>
If you don’t know what those tags are, it’s FreeMarker, a template engine used in many places in Nuxeo. If you look at the operation chain screenshot above, you see that the selected documents from the UI are stored in the ‘selectedDocuments’ context variable. So I can use the #list FreeMarker tag to iterate over the list of selected documents.
To get the document URL, there is currently no built-in method. We have to generate it ourselves. Fortunately, we have everything we need and it’s quite simple. A default URL in Nuxeo is made of the base URL http://yourServer/nuxeo/
, followed by nxdoc which is the name of the default URLCodec, followed by the name of the repository where the document is stored, followed by the id the document, and then the viewId.
Again we have everything needed in the FreeMarker context:
<a href="${baseUrl}nxdoc/${Session.getRepositoryName()}/${document.id}/${viewId}">${document.title}</a>
For me ${baseUrl} will render http://localhost:8080/nuxeo/
, _$_{Session.getRepositoryName() will render default
, ${document.id} will render something like 9811fa6f-5e42-46cb-ac4a-af341f1dab15
and ${viewId} will render view_documents
.
This should be all you need to know to send notification emails containing selected document links using Content Automation.