3

I want to inform the user if he changed the title (or path) of a structuregroup or folder by broadcasting a message, using the eventsystem. No message however appears in the messageCenter.

Eventsystem:

EventSystem.Subscribe<OrganizationalItem, SaveEventArgs>(OnOrgItemSave, EventPhases.Initiated | EventPhases.Processed | EventPhases.TransactionCommitted);
        public void OnOrgItemSave(OrganizationalItem orgItem, SaveEventArgs args, EventPhases phase)
        {
            if (phase == EventPhases.Processed)
            {
                        if (IsRenamed(orgItem, args) || (orgItem is StructureGroup && IsDirectoryChanged((StructureGroup)orgItem, args)))
                        {
                            args.ContextVariables["Signalr4TridionMessage"] = "Caution! You changed the name or path of this item. Don't forget to ......";
                        }
            }
            if (phase == EventPhases.TransactionCommitted)
            {
                if (args.ContextVariables.ContainsKey(Signalr4TridionMessage))
                {
                    string message = args.ContextVariables["Signalr4TridionMessage"].ToString();
                    SendMessage(message, orgItem);
                }
            }
        }
        private static void SendMessage(string message, IdentifiableObject CMSObject)
        {
            Session session = CMSObject.Session;
            JObject details = JObject.FromObject(new
            {
                creatorId = session.AccessToken.Id.ToString(),
                description = message
            });
            NotificationMessage notificationMessage = new NotificationMessage
            {
                Action = "tcm:EventSystem",
                SubjectIds = new[] { CMSObject.Id.ToString() },
                Details = details.ToString()
            };
            session.NotificationsManager.BroadcastNotification(notificationMessage);
        }

I followed the instructions found in the SDL Sites9 documentation and the NotificationHandler.js is as follows:

var notificationHandler = function(event){

    alert ("start notificationHandler");
        if (Tridion.MessageCenter.getInstance())
        {
            var title = "Message from me";
            var description = "hello world";
            Tridion.MessageCenter.registerNotification(title, description, true);
        }
};
alert("notificationhandler loaded");
var notificationBroadcaster = Tridion.Web.UI.Core.NotificationBroadcaster.getInstance();
alert("notificationBroadcaster=" + notificationBroadcaster);
notificationBroadcaster.addEventListener("notification", notificationHandler);
alert("eventlistener added");

All alerts are shown (except for the one in the function notificationHandler, so it seems that the event never fires).

Anyone any clues?

3
  • Did you find any error in the browser console? Maybe you can verify your set up and entry of extension on the system.config file once again. You can refer justsayantan.wordpress.com/2017/03/28/ui-notification-framework. Jul 17, 2019 at 14:43
  • What Tridion version do you use?
    – AntonM
    Jul 18, 2019 at 7:13
  • 1
    Thanks for your comments. We just solved this problem. The documentation does not (or on a very obscure place) mention that you have to enable this feature by setting this.properties.isEnabled = true; in the file \Tridion\web\WebUI\Core\Client\NotificationBroadcaster\NotificationBroadcaster.js. btw: this is about SDL Sites9 Jul 18, 2019 at 11:43

1 Answer 1

6

I know you've sorted out your problem, but I wanted to clarify on why this was not working for you for future reference.

In the SDL Sites 9, there is a known issue with the push notification mechanism in a scaled-out setup if the CM servers are behind a load balancer so the notification broadcaster was disabled by default.

You can enable it via:

If you have an extension leveraging the Notification API, you can enable it by hand by modifying the NotificationBroadcaster.js file, located in the web\WebUI\Core\Client\NotificationBroadcaster\ subfolder of %TRIDION_HOME%. After backing up the file, open it for editing, find the isEnabled property and set it to true. Then save and close the file. Next, in the web\WebUI\WebRoot\Configuration\ subfolder of %TRIDION_HOME%, open System.config and follow the XPath \Configuration\servicemodel\server. In the server element, increase the value of the modification attribute to notify client browsers to update their cache. Then save and close this file, too.

You can read more information about the issue and the workaround here.

1
  • 1
    For a future references: this issue is fixed in the upcoming Sites 9.1 where Notifications broadcasting is turned on out of the box.
    – AntonM
    Jul 19, 2019 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.