0

When sending a message from the EventSystem (in a single event and phase) to the notificationFramework, the message appears multiple times in the messageCenter. When sending a message from a Windows Forms Client the same thing happens. Code is similar to the post below. I verified that the notificationHandler is called multiple times. How can I fix that?

Here's my code:

        public void SubScribe()
        {
            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 (....) {}
                    args.ContextVariables[Signalr4TridionMessage] = "message to user";
                }
            }
            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
            {
                messageTitle = "Message from eventsystem",
                addressedUserId = session.AccessToken.Id.ToString(),
                messageText = message
            });
            NotificationMessage notificationMessage = new NotificationMessage
            {
                Action = "tcm:EventSystem",
                SubjectIds = new[] { CMSObject.Id.ToString() },
                Details = details.ToString()
            };
            session.NotificationsManager.BroadcastNotification(notificationMessage);
        }

see also: Notification Framework - Duplicated messages

2
  • Please copy your event handler code, it's possible it's called multiple times.
    – Atila Sos
    Aug 8, 2019 at 11:51
  • I copied the event handler code. Aug 19, 2019 at 10:48

0

Your Answer

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

Browse other questions tagged or ask your own question.