# Basic notification pattern

**URL:** <https://community.simplicite.io/t/basic-notification-pattern/2556>\
**Category:** Tips and tricks\
**Created:** [August 31, 2020, 3:58pm UTC](https://community.simplicite.io/t/basic-notification-pattern/2556 "2020-08-31T15:58:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![scampano](https://community.simplicite.io/user_avatar/community.simplicite.io/scampano/32/10010_2.png) [@scampano](https://community.simplicite.io/u/scampano)\
**Post date:** [August 31, 2020, 3:58pm UTC](https://community.simplicite.io/t/basic-notification-pattern/2556/1 "2020-08-31T15:58:54Z")

</div>

It is a common use case to have a notification system for the app. A good pattern is to have a centralized “Notification” object that refers to the object that triggered the notification via an “Object” attribute (which stores the object via the object name and row\_id). The notification object can include mechanisms to optionally send emails based on user preferences, rules etc. _The code to manage the notifications is app-specific and not covered in this tutorial._

 ![notif](https://community.simplicite.io/uploads/default/original/2X/a/ab4db2ef15931a3f0d45135d842f7ca9bab3aa49.png)

Configuration would go as follows:

```auto
- Object : MyNotification
- Attributes : 
  - ntfDatetime
  - ntfUsrId
  - ntfObject
  - ntfIsRead
  - etc.

```

We would then proceed to add a domain for our app, with _no homepage_ and _containing a single object_ : the notification object. This results on the platform adding a menu item which gives direct access to the list.

The last bit is to display a counter of unread notifications in the menu, which can be done by modifying the general JS script (available through Interface \> Dispositions : **responsive** \> Resources : **SCRIPT** ) like so:

```javascript
(function($) {
	$(document).on("ui.ready", function() {
		setNotifications(); // at startup
		$ui.options.defaultContentLoad = setNotifications; // on each page change
	});
	
	function setNotifications(){
		var ntf = $ui.getApp().getBusinessObject("MyNotification");
		ntf.getCount(function(){
			$('ul.main-menu').find('a[data-domain=\'MyNotifDomain\'] > .text').html('Notifications ('+ntf.count+')');
		}, {ntfIsRead: '0'})
	}
})(jQuery);

```

---

<div class="post-metadata">

**Author:** ![Francois](https://community.simplicite.io/user_avatar/community.simplicite.io/francois/32/6448_2.png) [@Francois](https://community.simplicite.io/u/Francois)\
**Post date:** [September 2, 2020, 2:55pm UTC](https://community.simplicite.io/t/basic-notification-pattern/2556/2 "2020-09-02T14:55:40Z")

</div>

> [@scampano](#):
>
> `$ui.options.defaultContentLoad = setNotifications; `

It might generate too many calls, or never refresh if the user doesn’t do anything for several minutes.  
I would have used a regular interval instead to reload the counter every minute:

`setInterval(setNotifications, 60000)`
