How-to: Create notifications by using workflows/logic hooks

Hey everyone,
we did some testing with these kind of user notifications:
chrome_nRG9aipQqe
We found two working approaches to create them, both are described below:

1st Option: Using Workflows

This approach enables most users to create those notifications without modifying/adding php-code. To get it working, a new custom field ( internal_link, type TextField) is needed within the selected “WorkFlow Module” (e.g. accounts.). For this example, we create notifications for each newly added account:

The workflow configuration in summary:

  • Basic
    • WorkFlow Module: Accounts
    • Status: Active
    • Run: Only on save
    • Run on: New Records
    • Repeated runs: unchecked
  • Conditions:
    • dependent from the current use case, therefore not described here
  • Actions:
    • 1st action: Calculate fields
      • Parameter: ID (should be {P0})
      • Relation parameters: not needed
      • Formulars:
        • field: internal_link
        • formula: index.php?module=Accounts&action=DetailView&record={P0}
    • 2nd action: create Record,
      • record type: Alerts
      • fields should be set to:
        • “Assigned to” / “Field” / “Assigned to”
        • “Description” / “Value” /
        • “Name” / “Field” / “Name”
        • “Is Read” / “Value” / unchecked box
        • 1st label “type” / “Value” / “Accounts”
        • 2nd label “type” / “Value” / “info”
        • 3rd label “type” / “Field” / “internal link”

Now, a notification should be shown to the assigned user of each newly created account:
vivaldi_T0ksEw5F91

Those three 'type' options are a bit confusing, here are some more details:

apparently, some labels are missing/wrong:


as you see, the first field indicates the target module, the second one the kind of warning and the last one is the redirect url which is used as target url.

2nd Option: Using logic hooks

The first approach has some disadvantages (e.g. adding a custom field, limited possibilities to add content). Therefore, I tested this method as after_save-Hook (new example: get notifications each time a new contact has been added):

<?php
class WarningGenerator{
    function createNewContactWarning($bean, $event, $arguments){
        //new bean or already existing bean?
        if ($bean->fetched_row == false) {
            $url = 'index.php?module=Contacts&action=DetailView&record=';
            $alert = BeanFactory::newBean('Alerts');
            $alert->name = 'new contact!';
            $alert->description = $bean->name . ' has been added.';
            $alert->assigned_user_id = $bean->assigned_user_id;
            $alert->is_read = 0;
            $alert->target_module = 'Contact';
            $alert->type = 'info';
            $alert->url_redirect = $url . $bean->id;
            $result = $alert->save();
        }
    }
}

result after creating a contact:
vivaldi_KWxWS9bMOv

Both approaches are clickable and redirect to the respective object.

Note: for attribute “type” we saw that two values work (info and warning). The first screenshots were taken with type = info, while warning looks like:
vivaldi_Nvl8xj1G1o

If you have concerns, additional ideas or improvements, please keep this thread updated :slight_smile:

kind regards,
d.

10 Likes

Thanks @crmspace,

This looks really cool!

Great tutorial, this should be in the official documentation. Thanks @crmspace!

There is this:

The official docs are community-maintained, anybody can edit them (like a wiki).

Dear @crmspace thank you very very much.
About first option: Using Workflows

when you say

  • field: internal_link

do you mean a custom field?

indeed, this field is used to store the link. It’s a custom field that I’ve added for this purpose, but you do not need to add it to any view.

1 Like

4 posts were split to a new topic: Workflow: Date conditions

Hi,
I follow your step it working no problem,but it append data again and again.
For example:- i have total 207 payment security only 17 are expired after 45 days,so i check the data from database that is 17 only,same i try from code 17 name coming no problem but after some second again 17 append with that after some second again 17 append with old how, i resolve this kindly help me.
Thanks

How to create an Alert :bell: for salesperson?

For example, a salesperson should be able to get alert for all of his customer accounts and activities like emails, calls, events, meetings, tasks, etc.

Is there any other way to achieve this functionality? I would like to have something easier to implement.

Thank you for help in an advance!!! :heart_hands: :heart_hands: :heart_hands: