Content Hub Tip #26: Sending notifications with JavaScript

 

Content Hub Tips logo

In the Content Hub, Sitecore ensures the user is notified of the outcome of their actions. This user is notified via the internal notifying system. It can be triggered from almost anywhere within and outside the Content Hub. It's possible to send a notification within an internal Script, via the Rest API, Web SDK, or JavaScript. Today I will show how you can leverage the notification part within JavaScript.

Example of a succes notification

The following code shows how to send a success and a failure notification. The object really speaks for itself. The Text parameter is the text that will be displayed within the browser. The Level parameter controls the looks of the notification. It has three levels: succes, danger and info. Last but not least, is the parameter if the notification can quickly be dismissed, via the canBeClosed parameter. When set to true, the user can close the notification. If set to false, the user has to wait before the notification disappears by itself.

options.messageBoard.addMessage({
    "text": 'Succes notification.',
    "level": "success",
    "canBeClosed": true
});

options.messageBoard.addMessage({
    "text": 'Failed notification.',
    "level": "danger",
    "canBeClosed": true
});

For more options for the External page components, check out the documentation.

Happy codin'!