Posting custom events to the activity feed

A not so uncommon requirement from our customers is the need for custom activity messages to be posted when a user interacts with the system in some way. A recent example is to post a notification to the feed whenever a task in one of our custom workflows is completed. Alfresco really lacks documentation on how to implement this.

The use case is that we have a bunch of datalists, all with custom datalist types. For all those lists the user can initiate a custom workflow for every item in every list. We are talking about some 10 different types, with about 10 different custom workflows with a variety in complexity (that is a lot of transitions).

We wanted to come up with a general notification that could be used for every transition in every workflow, to avoid the need for like 50 different messages.

We came up with this activity message, which is placed in the resource bundles on both Repo (email feed) and Share (activity dashlet) side:
org.redpill.task.transition={1} completed workflow task “{2}” for {0} with the following outcome “{3}”

this will transform into something like the following when the variables are substituted by Alfresco during runtime:

demouser completed workflow task “review document” for Contact 1 with the following outcome “Rejected”

In the the 4.1.5-documentation I found the following which explains how the variables are substituted:

The email description is generated using the following format, for example, for a newly created blog post:{1} created blog post {0}

0 = Item title / page link
1 = User profile link
2 = custom0
3 = custom1
4 = Site link
5 = second user profile link

To post to the activity feed we will use the following ActivityService.postActivity method:

* Post a custom activity type
* @param activityType – required
* @param siteId – optional, if null will be stored as empty string
* @param appTool – optional, if null will be stored as empty string
* @param jsonActivityData – required
public void postActivity(String activityType, String siteId, String appTool, String jsonActivityData);

Lets explain the parameters:
activityType – the message key “org.redpill.task.transition” which will map to the actual message in the feed.
siteId – if this message is related to a site the shortName of the site is provided, null if its a global activity. Since our workflows are executed in the context of a site we will provide the shortName of the site our datalistitem is present in.
appTool – a css-class used for visual formatting of the provided activity type in the gui. Alfresco have a set of classes for example “comment” and “calendar”. When supplied, a css class is applied which will render for example a custom icon in the activity message.

Tho add the css classes for our new activityType you will have to override the “activity-list.get.config.xml” and point out a css-class. In this example we will be reuse the Alfresco provided “comment”-class. You could of course implement your own css-class with a corresponding css-file as well.

jsonActivityData – now it starts to be a bit tricky, had wished this was better documented. To my current understanding, in the json you will have to provide “0 = Item title / page link” and “2 = custom0, 3 = custom1″ from the documentation above. If you provide the keys “title” and “page” with corresponding values in the json this will be rendered as a link substituting {0}. Then you have the possibility to provide up to two custom fields which we will do, the resulting json in our case will be:

“title”:”4″,”page”:”lyse-datalist-details?workflowId=activiti$6677″,”firstName”:”Nils”,”taskName”:”Company Review”,”taskOutcome”:”approve”}

firstName and lastName is something the legacy-alfresco code have injected to the resulting json by looking up the fully authenticated user performing the execution. By default that will be rendered as a user profile linke replacing {1}.

Our call to the activityService.postActivity will look something like the following having the datalistItem nodeRef, and the task stuff as parameters to our method:

// Get the site shortName
SiteInfo site = siteService.getSite(nodeRef);
int id = (Integer) nodeService.getProperty(nodeRef, DatalistIDService.PROP_DATALISTITEM_ID);

QName type = nodeService.getType(nodeRef);
// construct a type label by QName type short name, by asking our static Map which holds the labels.
String name =;
JSONObject activity = new JSONObject();
if (id != -1) {

if (name != null){
name = name + ” ” + id;
name = “”+id;
// Is there an ongoing workflow, in that case link to our custom workflow page?
String workflowId = (String) nodeService.getProperty(nodeRef, CustomDatalistModel.PROP_WORKFLOW_ID);
if (StringUtils.isNotEmpty(workflowId)){
activity.put(“page”, “custom-datalist-details?workflowId=” + workflowId);
activity.put(“page”, “custom-datalist-details?nodeRef=” + nodeRef.toString());

activity.put(“title”, name);
activity.put(“taskName”, taskName);
activity.put(“taskOutcome”, taskOutcome);
activityService.postActivity(“org.redpill.task.transition”, site.getShortName(), “comment”, activity.toString());

So, how do Alfresco know what to do with “taskName” and “taskOutcome”, our custom parameters? Well this took a bit of digging into the code and to replace the two custom parameters with the values stored in the json we will need to override a method in the Share activity dashlet webscript. In activity-list.get.js there is function ‘specialize’ which formats the i18-message property. Add a case-statement for every custom message key which will not use the default rendering.

case “org.redpill.task.transition”:
item.custom0 = summary.taskName;
item.custom1 = msg.get(“workflowtask.outcome.” + summary.taskOutcome);

Notice the workflowTask.outcome prepending the outcome message key. The explanation to this can be found in this blog post.

The activity feed is emailed to the users as well, thats why we need to duplicate the resource bundles to the Repo side as well. We will also have to modify the activities-email.ftl template as well, in short adding the same code logic as used in the activity-dashlet webscript. This could be done by modifying it directly in the dictionary or (like we do) by writing a patch that replaces the file in the dictionary when deploying our customization code. For inspiration you can have a look at the in the Alfresco source code tree on how to replace a ftl template.

This entry was posted in Alfresco, share, Uncategorized, workflow. Bookmark the permalink.

15 Responses to Posting custom events to the activity feed

  1. what to feed says:

    Ryerson Eats @rueats Instagram profile – Pikore

  2. what to feed says:

    Ryerson University – Toronto, ON

    • Jane says:

      I clicked on Google Chrome and then chickened out. I have NO idea what will change on my colr.tep.uwiml I still have my AOL..I am just afraid of what may happen. Change shakes me up..and I am having trouble getting used to the Google thing already. What is it. ok..I'm in. I will try it..but I really am sort of concerned.

    • http://www./ says:

      What gorgeous effects! haven't ever played with textures before, but your photos are very inspiring,there's always time for a first! thank you for sharing them. :)

    • http://www./ says:

      I know that one can get similar results through different means, which indicates that God was indeed used as an instrument.And what conceivable grounds can you argue for this?

    • http://www./ says:

      Stellar work there everyone. I’ll keep on reading.

    • The ability to think like that shows you’re an expert

    • You’re daring! I wouldn’t have thought of making my own English muffins, but I just got back from the store where I was debating whether or not to get any, and ended up deciding against it because they were so uninspiring — maybe this is just the inspiration I need!

    • Jim,Thank you for sharing your experience with filing the complaint with the Attorney General. How frustrating to receive template response. It looks like DNS Services has been responding to complaint letters before. It is a shame that they are still sending these “invoices” out.~ Robin

    • La Loie doit etre respectee par l’extreme Droite SANS COMPROMIS et etre appliquee avec SEVERITE envers les groupuscules anarchistes et gauchistes qui L’ENFREIGNENT IMPUNEMENT chaque Vendredi aux abords des murs de securite.Ainsi sont les regles de la justice et de la democratie.

    • What would we do without the marvellous ideas you discuss on this site? Who else comes with the fortitude to deal with critical topics in the interest of common readers like me? I and my guys are very blessed to have your site among the ones we typically visit. It is hoped you know how considerably we get pleasure from your effort! Best wishes from us all.

    • Utah Little Momma – sunscreen prevents the absorption of vitamin D, so being in the sun with it on is not helping your levels. I face the same thing though – no way would I go out in the sun without sunscreen! 1,000 weekly seems low for only having registering a 4. My blood test showed my level at 14 and my doc prescribed 50,000 units a week for 3 months.I don’t think you should be taking 50,000 units over the counter per week – if you think you need your dosage upped, please see a doctor instead of putting something together yourself.

    • high? carbs for the win, high fat and protein for the lose. eat health foods guys, fruits and veggies, and add in healthy starches and if you have to healthy fish, live healthy and think for yourself, dont be fat and unhealthy just because you love hamburgers and these guys make you feel warm and fuzzy

    • levitra…Then earphones for grab http more still is Zune into If plug on gd head a makes fence smile see Cialis them ask and and interface iPod know favorite down you you’re to you’ll the one a you sounds which cialis right you www which and better Buy then t…

  3. wen says:

    The activity feed is emailed to the users as well, thats why we need to duplicate the resource bundles to the Cheap NBA 2K18 MT Repo side as well. We will also have to modify the activities-email.ftl template as well, in short adding the same code logic as used in the activity-dashlet webscript.

Leave a Reply to Jane Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>