Notify Users When They get Tagged in Activity Stream Window

Idea created by Shijin Krishna on Nov 1, 2015

    As we know Sugar 7.x has the option to tag Users while creating a new post in Activity Stream window out of the box.But unfortunately there is no in built functionality to notify the user once he/she get tagged.


    Don’t worry! In this article we are going to see how can we send an email alert or create a notification in Sugar notification list for a user when he or she get tagged in Activity Stream by another Sugar user.



    In the above image user Venkat has been tagged by Administrator under the Activity Stream window of a lead.See below Venkat’s Notification Indicator.


    Once you click on it, system will take you to the notification detail view.





    In description you can see the comment user has wrote during the time of tagging.By clicking the Lead’s name user can directly navigate to the activity stream window under the lead’s record and update his/her comments.


    Let’s start implementing this.


    Step 1

      Copy file ~clients/base/views/activitystream-omnibar.js to custom/clients/base/views/activitystream-omnibar.js and modify the addPost method as below


    addPost: function() {

            var self = this,

                parentId = this.context.parent.get("model").id,

                parentType = this.context.parent.get("model").module,

                attachments = this.$('.activitystream-pending-attachment'),

                $submitButton = this.$('button.addPost'),


            if (parentType == 'Home' || parentType == 'Activities') {

                parentType = null;

                parentId = null;


            var payload = {

                activity_type: "post",

                parent_id: parentId || null,

                parent_type: parentType,

                data: {}


            if (!$submitButton.hasClass('disabled')) {

       = this.getPost();

                if ( && ( > 0)) {


                    bean ='Activities');

          , {

                        success: function(model) {

    //Custom code added to make an api call to notify the tagged user.

                var comment=$.trim(model.get('data')['value'].split(']').pop());

                var users=model.get('data')['tags'];

                var module_name=(!_.isUndefined(model.get('data')['object'])) ? model.get('data')['object']['module'] : '';

                var record_id=(!_.isUndefined(model.get('data')['object'])) ? model.get('data')['object']['id'] : '';






                            model.set('picture', app.user.get('picture'));


                            self.context.trigger('activitystream:post:prepend', model);


                        complete: function() {



                        showAlerts: true







    Step 2


    Now create a new file in the following path createTagNotificationApi.php


    and add the below code


      if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

      class createTagNotificationApi extends SugarApi{

        public function registerApiRest(){

          return array(

            'createNotification' => array(

              'reqType' => 'POST',

              'path' => array('Notifications','createNotification'),

              'pathVars' => array(),

              'method' => 'createNotification',

              'shortHelp' => 'Custom Api to create a notification for a user whenever he is getting taged in activity stream',

              'longHelp' => '',




        public function createNotification($api,$args){

          foreach($args['users'] as $user){

            global $app_list_strings;

            global $current_user;

            $notification= BeanFactory::newBean("Notifications");










            $notification->name=trim($current_user->first_name." ".$current_user->last_name)." has mentioned you in his/her new post";



          return "success";




    Note : To send an email alert you can customize the createNotification() method with the custom code to send an email.Primary email id of the user can be fetched as below.

    $userBean = BeanFactory::getBean(Users,$user['id']);

    $primary_email = $userBean->email1;


    Step 3


    Navigate to Admin > Repair > Quick Repair and Rebuild