Hey everyone,
we did some testing with these kind of user notifications:
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}
- field:
- Parameter: ID (should be
- 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”
- record type:
- 1st action: Calculate fields
Now, a notification should be shown to the assigned user of each newly created account:
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:
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:
If you have concerns, additional ideas or improvements, please keep this thread updated
kind regards,
d.