Sugar Notifications in Action

hatimalam —  March 14, 2016

Here is a guest post from Hatim Alam from BHEA, an Elite SugarCRM Partner, and is a certified Sugar Developer Specialist. Hatim shares some ideas for getting creative use out of Sugar Notifications.  Share your own ideas in comments below!

In this post, we are going to look into different scenarios where Sugar Notifications can be of great help. For example, It can be used to notify user when new post or comment has been created on the Activity Stream or on execution of custom job or on triggering of API endpoint or implementing approval/review workflow.

We will create Sugar Notification for each of these scenarios and learn how easy it is to use and implement.


New comment in Activity Stream

What are Sugar Notifications?

The Notifications indicator is available to all Sugar users and is located on the upper right of the screen next to global search.

The number displayed in the notifications box indicates the number of messages with a status of “Unread”. A “0” will appear if there are no unread notifications.

Open the Notifications dropdown and click “View Notifications” in order to see all notifications in a list view.


Activity Stream notification in Notifications drop down

Create Sugar Notifications on new posts or comments in the Activity Stream

Editor’s Note:  Pedro Bazan had published popular a logic hook for adding notifications whenever a user is mentioned in an Activity Stream.

The following steps will create new before_save logic hook on Activities bean within Activity Stream module. Through this logic hook, we will create a new notification whenever a user posts a new comment.

Step 1: Create before_save Logic Hook extension definition


Step 2: Create the Logic Hook action method

As defined in our logic hook extension above, now we need to create a file where we can define our logic hook function.  In this action, we will check if any new post or comment has been posted to Activity Stream.

Usually, there are multiple types of activities in Activity Stream – link, unlink, create, update and post. We will be checking if the activity type is a post.  The post activity type is associated with new posts or comments within an Activity Stream.


Create Sugar Notifications to update status of data synchronization

We have many situations where we integrate Sugar with external applications and expose our custom APIs to update data in Sugar as external changes happen. We can use notifications to increase user awareness of these changes. For eg; we can update contact information and notify the assigned user using Sugar Notifications.

Step 1: Create custom endpoint in Sugar


Create Sugar Notifications to implement approval or review workflows

Sugar Notifications can be very handy to implement approval/review workflow and notify a user or a user’s manager if any specific condition satisfies. For eg: the assigned user’s Manager gets a notification when an opportunity is created with a discount > 25%.

Step 1: Create before_save logic hook extension definition


Step 2: Create the logic hook action method

Here, we will check if opportunity discount percentage is >25%, we will notify assigned user’s Manager using Sugar Notifications


Se how easy it was to create Sugar Notifications? Sugar Notifications are a great tool for various other actions as well.  You can use them with custom APIs, logic hooks, Sugar Jobs, etc, in order to notify users of record assignment, new record creation, record update, job status, etc.

Try out some ideas on your own and let us know what you come up with in the comments below!


Record view for new Activity Stream notification

Quick Tip: Check out this SugarCRM Knowledge Base article for adjusting Sugar Notification Delay – Setting Sugar’s Notification Delay



Open source web developer and nothing much ;)

8 responses to Sugar Notifications in Action


    It helped me alot! Thank you so much..

    1 quesiton, as I have implemented your code I can see the notification in notification module. But, Why I didn’t get the Alert? Even the Number of Notifications at top right corner still remains (0).


      Hi Hammad,

      Glad to know it helped you 🙂
      Please make sure you are not setting is_read=1 or true (by default, it is false or 0).
      Let me know if this works.

    Shijin Krishna March 19, 2016 at 9:52 am

    Great Post Hatim!

    Here is another scenario where we can make use of Sugar Notifications.

    Create Sugar Notifications to update the Admin user If any of the Scheduler Job Fails.

    Step1: Job failure Logic Hook Extension Definition


    Step 2: Create the logic hook action method
    name = $bean->name.” – failed in cron run”;
    $notification_bean->description = “Oops!! Job (“.$bean->name.”) failed in cron run!;
    $notification_bean->assigned_user_id = ‘1’; //notification will be shown to Admin user
    $notification_bean->severity = “warning”;
    $notification_bean->is_read = 0;

    //you can add conditons based on $bean->scheduler_id to set notifications only if a specific job fails.



    Looks like beginning of my previous comment is trimmed off.

    Anyway below is the sugar documentation on how to add a job queue logic hook. You can just add the notification create logic to hook method.



    Hi, I have noticed that you refer to “custom/modules/Opportunities/customLogicHook.php” in “custom/Extension/modules/Opportunities/Ext/LogicHooks/check_opp_discount.php” but the name of the referred file is “custom/modules/Opportunities/customLogicHooks.php” with a ‘s’ at the end of the filename.


      Hi Artur,

      Thank you for pointing out that typo. I have fixed it now. Logic hook filename should be exactly same as what we declare in logic hook “custom/Extension/modules/Opportunities/Ext/LogicHooks/check_opp_discount.php”.