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.

5 Likes

Thanks @diligent,

This looks really cool!