5

I would like to throw a notification message in the CME message center from my workflow external activity TBB.

I am just trying to do this but not sure this is possible. I can do this with help of event system or GUI extension. But trying to see if I can do it with the TBB (workflow external activity) itself.

So, I am trying to get the Tridion Page object and register some notification as below. But I am not able to get the Page object. Is there a way to do this?

page = System.Web.HttpContext.Current.Handler as Page;
page.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", "<script type='text/javascript'>$messages.registerNotification(\"Hello world\");</script>");
  • 1
    I suggest you edit your question and supply a few more details like your TBB code, since the two lines of code you have added now don't give any detail. – Bart Koopman Nov 16 '17 at 8:58
  • Bart i can put, i have automatic decision activity in that i am just checking the user. If the user is expected then am just finishing the activity. If the user is not the expected one. i want to throw the notification and finish the activity. so, trying to throw the notification in the message center. – Jey Nov 16 '17 at 16:09
  • May I ask why you're not using Groups for this - or is there some specific business logic? We had a scenario where the approval of step X could not be undertaken by the approver of step X-1 - in which case we sent a notification to the CMS given them a jolly good telling off. – Dylan .. Mark Saunders Nov 16 '17 at 16:16
2

I have implemented the logic for component/page update notification using event handle.

please find below source code.

Step1:

Create a new SDLResponder.js file

SDLWeb.ContentManager.SDLResponder = function SDLResponder() {
    Tridion.OO.enableInterface(this, "Tridion.ContentManager.SDLResponder");
    this.addInterface("Tridion.MarshallableObject");
    this.addInterface("Tridion.InitializableObject");
    this.initialize();
};

SDLWeb.ContentManager.SDLResponder.IDENTIFIER = "tcm:SDLResponder";

SDLWeb.ContentManager.SDLResponder.prototype._initialize = function SDLResponder$_initialize() {
    this.callBase("Tridion.InitializableObject", "_initialize");
    SDLWeb.Web.UI.Core.NotificationBroadcaster.getInstance().addEventListener("notification", this.getDelegate(this.handleNotification));
};

SDLWeb.ContentManager.SDLResponder.prototype.handleNotification = function SDLResponder$handleNotification(event) {
    if (event.data !== null) {
        var id = Tridion.ContentManager.UserSettings.getJsonUserSettings(true).User["@ID"];
        var data = event.data;
        if (data.details.userId !== null && data.details !== undefined) {

            if (data.details !== null && data.details.userId !== null && data.details.userId == id) {
                switch (data.action) {
                    case "PageSave":                       
                        //MessageCenter$registerNotification(title, description, local, modal, htmlDescription) for hyperlinks to work send true for html description
                        $messages.registerNotification("Notification", "" + data.details.messageNotification, true, null, true);
                        break;
                    case "ComponentSave":

                        //MessageCenter$registerNotification(title, description, local, modal, htmlDescription) for hyperlinks to work send true for html description
                        $messages.registerNotification("Notification", "" + data.details.messageNotification, true, null, true);
                        break;
                }
            }

        }
    }
};

if (!$models.getFromRepository(SDLWeb.ContentManager.SDLResponder.IDENTIFIER)) {
    $models.createInRepository(SDLWeb.ContentManager.SDLResponder.IDENTIFIER, "SDLWeb.ContentManager.SDLResponder");
};

Step2: Added below line into editor.config:

<cfg:file type="script">/Notifications/SDLResponder.js</cfg:file>

**

Event handler code for component update:

**

 public void SendSoftNotificationMessage(Component component)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string notificationmessage = string.Empty;
            string softNotificationMessage = string.Empty;
            string emailnotificatioinmessage = string.Empty;          
            Dictionary<string, object> componentDic = new Dictionary<string, object>();
            var session = component.Session;
            componentDic.Add("userId", session.AccessToken.Id.ToString());
            componentDic.Add("reasons", emptyarray);                   
            softNotificationMessage = string.Format(EventHandlerConstants.Message, component.Title ));          
            notificationmessage = string.Format(EventHandlerConstants.SoftNotificationMessage, component.Title, softNotificationMessage);
            componentDic.Add("messageNotification", notificationmessage);
            string jsonString = serializer.Serialize((object)componentDic);
            var message = new NotificationMessage
            {
                Action = "ComponentSave",
                SubjectIds = new[] { component.Id.ToString() },
                Details = jsonString
            };
            session.NotificationsManager.BroadcastNotification(message);         
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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