Adds notification for one or all users.
Syntax
CommonFunctions.addNotification(dynamic message, dynamic title = null, dynamic icon = null, dynamic url = null, dynamic expire = null, dynamic permissions = null, dynamic newWindow = false)
Arguments
message
notification text
title
optional notification title
icon
optional icon, can be in one of three formats:
- URL: "https://website.com/images/image.png" or "images/file.gif"
- Bootstrap icon: "glyphicon-film", "glyphicon-hand-right"
The full list of available Bootstrap icons.
- Font Awesome icon: "fa-envelope", "fa-user"
The full list of available Font Awesome icons.
url
optional URL. When specified, a click on notification sends the user to the specified address. See makePageLink function
expire
optional expiration date and time for the message. Can be either datetime in "YYYY-MM-DD hh:mm:ss" format, or a number of minutes the notification should be visible.
Examples:
"2022-01-10 00:00:00" or 1440 for 24-hour period
permissions
Optional, null by default. Can be one of the following:
- not specified or null - all users will see this notification
- string i.e. "admin". The value is interpreted as a username. Only the specified user will see the notification.
- array with keys "user" and optional value "provider"
$permissions["user"] - username. Only this user will see the notification.
$permissions["provider"] - when the user is a database user, whose username and password are stored in a database table, this parameter must be empty. When the user is logged via from Active Directory, OpenID, Google etc, then put the two-letter security provider code here. You can find it on the 'Security screen' under the provider settings dialog.
- array with key "group"
$permissions["group"] - only members of this group will see the notification
- array with keys "table" and "page"
$permissions["table"] - name of the table, custom view, report or chart name.
$permissions["page"] - page name like "list", "list1" etc.
When this type of permissions is specified, only those users who have access to the specified page will see the notification.
newWindow
Optional, false by default. When true, the notification link will be open in a new browser tab. When false, the link will be open in the same browser tab.
Return value
No return value
Example 1
This example shows how to add a notification for all users when a new record added to the Categories table. This code needs to be added to AfterAdd event of the Categories table.
CommonFunctions.addNotification( "New category added: " + values["CategoryName"].ToString() , "New category", "fa-envelope", makePageLink( "categories", "view", keys) );
Example 2
Add notification with with link opened in new window.
CommonFunctions.addNotification( "It's time to check your mail", "Mail check", "glyphicon-envelope", "https://mail.google.com", null, null, true );
Example 3
Add notification visible only to 'bob' user.
CommonFunctions.addNotification( "Wake up, Bob", "Morning", null, null, null, "bob", true );
Example 4
Add notification visible only to 'Administrator' user from Active Directory
dynamic permissions = XVar.Array();
permissions["user"] = "Administrator";
permissions["provider"] = "ad";
CommonFunctions.addNotification( "Good night, Admin", "Night", null, null, null, permissions, true );
Example 5
Add notification visible only to users who have access to Orders - Edit page
dynamic permissions = XVar.Array();
permissions["table"] = "orders";
permissions["page"] = "edit";
CommonFunctions.addNotification( "Update your orders, guys", "Order", null, null, "orders_list.php", permissions, true );
Example 6
Add notification visible only to users in specific group.
dynamic permissions = XVar.Array();
permissions["group"] = "<Admin>";
CommonFunctions.addNotification( "Let's have a coffee break", "Admins only", null, null, null, permissions, true );
See also: