I am using SDL Web 8.5 and I want to broadcast a warning message to the user upon saving a component. I am using the event system to trigger the message on save. However, after setting everything up, no message appears in the message center in the user's browser when a component is saved.
EventSystem:
EventSystem.Subscribe<Component, SaveEventArgs>(SendMessageUponSave, EventPhases.Initiated);
private void SendMessageUponSave(Component component, ItemField itemField)
{
var session = component.Session;
var message = new NotificationMessage
{
Action = "example:save",
SubjectIds = new[] { component.Id.ToString() },
Details = string.Format(WARNING_STRING, x, fieldName)
};
session.NotificationsManager.BroadcastNotification(message);
}
}
The NotificationHandler.js is as follows:
console.log("The NotificationHandler.js file has been loaded by this browser.");
var notificationHandler = function(event)
{
console.log("The NotificationHandler.js has detected that a notification event has occurred."+event.data.action );
console.log(event.data );
// only proceed if the message is the message we broadcasted ourself from the CM eventhandler
if (event.data.action !== "example:save")
{
return;
}
console.log("The NotificationHandler.js has detected that a notification event has occurred with the action of example:save.");
var userSettings = Tridion.ContentManager.UserSettings.getInstance();
// only process the message when it is meant for this user
if (event.data.details.creatorId === userSettings.getUserId())
{
if (Tridion.MessageCenter.getInstance())
{
var title = "Item saved.";
var description = `Item '${event.data.details.description}' was saved`;
Tridion.MessageCenter.registerNotification(title, description, true);
}
}
};
var notificationBroadcaster = Tridion.Web.UI.Core.NotificationBroadcaster.getInstance();
notificationBroadcaster.addEventListener("notification", notificationHandler);
we followed these steps to configure the UI model extension
Create a new folder in the folder %Tridion Home%\Web\web\WebUI\Models\ on your SDL Web instance
Update the models section in the %Tridion Home%\ Web\web\WebUI\WebRoot\Configuration\System.config configuration file to load the UI model extension
Increase the modification attribute on the server element by 1 to force the browsers to get a new version of the code.
The console.log at the beginning of the NotificationHandler.js logs just fine, and the second one also logs once in awhile with the event.data.action output of 'tcm:updated' but we do not get any logs with 'example:save'. We tried checking for the answer in this TREX post: (Cannot get broadcasting to messagecenter to work that was only applicable to sites 9) but no luck.
Any clues?