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:

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:

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:

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.

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 ActivitiesTemplatesUpdatePatch.java in the Alfresco source code tree on how to replace a ftl template.

69 Responses to Posting custom events to the activity feed

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.

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

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…

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. BUYnba2k.com 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.

g2RmnM Thanks for another wonderful post. Where else could anyone get that type of information in such an ideal way of writing? I have a presentation next week, and I am on the look for such information.