cancel
Showing results for 
Search instead for 
Did you mean: 

How do I add an email notification when comments are added?

prachi379
Champ on-the-rise
Champ on-the-rise

I would like to create a new notification that is sent to the author of the document and the commenter when a new comment is added on a document. Can anyone let me know how I can achieve this?

6 REPLIES 6

angelborroy
Community Manager Community Manager
Community Manager

You can develop a custom behaviour for that.

Listen to 'onContentUpdate' event for 'ForumModel.TYPE_POST' types and send the email by using an action 'MailActionExecuter.NAME'

Hyland Developer Evangelist

idwright
Star Collaborator
Star Collaborator

Probably the easiest way to do this is to create a rule that is configured to run a script when the document is updated.

From the script you can then use the mail action e.g.

  var template = "Data Dictionary/Email Templates/Notify Email Templates/xxxxx.ftl";

  var mail = actions.create("mail");

  var creator = document.properties["cm:creator"];

  var peep = people.getPerson(creator);

  mail.parameters.to = peep.properties["cm:email"];

  mail.parameters.subject="Document changed: "+document.properties.title;

  mail.parameters.template = companyhome.childByNamePath(template);

  mail.execute(document);

You don't need to use a template but it's nicer if you do.

Interesting, where do you include such rule? At 'Repository > Sites'?

Hyland Developer Evangelist

I think the original question was asking about a document rather than a discussion post.

If adding the rule to site discussions then, yes in Repository > Sites ....

I've wrapped up Discussions notifications in an add on GitHub - malariagen/alfresco-discussions: Customizations to Alfresco Site Discussions that does rather more than just send out an email.

I'm not sure of the pros and cons of behaviour vs rule but in this case I think a rule gives more flexibility.

In fact, a document comment is modelled as a discussion post: they both are sharing content model.

So, I have to add that the behaviour should check if the new POST is happening inside 'documentLibrary' component.

IMO, behaviours are more efficient than rules, as they are only listening to events inside node lifecycle. However, rules must consider all containing folder hierarchy also as triggering condition, which in the end can involve too much overload for the system.

Hyland Developer Evangelist

Interesting about the shared content model.

I wouldn't think it's a good idea to use a rule everywhere, so I agree a behaviour is probably better in that case.

It might be easier to check if the post is not in a discussion.