locked
SCSM 2012 RC - Using the Action Log in Email Notifications RRS feed

  • Question

  • Hi All

    We have recently upgraded from SCSM 2010 to 2012 RC. After some effort getting Email processing working, I've noticed that the old format action log no longer works for sending out emails.

    In 2010, it was possible to print the entire action log sequentially in a notification email, using something like this:

    <Group>
    <pre>
    $Context/Path[Relationship='CustomSystem_WorkItem_Library!
    System.WorkItem.TroubleTicketHasActionLog' TypeConstraint='CustomSystem_WorkItem_Library!
    System.WorkItem.ActionLog']/Property[Type='CustomSystem_WorkItem_Library!
    System.WorkItem.ActionLog']/Description$
    </pre>
    </Group>
    <br>

    However this no longer works in 2012 RC, it looks like the entries in the action log are split into 3 categories:

    • Incident > Has Analyst Comment > Comment (Analyst Comments)
    • Incident > Has User Comment > Comment (Affected User Comments)
    • Incident > Trouble Ticket has Action Log > Comment (System actions such as Incident Assigned)

    SO, the question is, in SCSM2012 RC, how can i aggregate these action log entries into 1 sequential list for use in a notification email?

    Thanks in advance for any suggestions!


    Have you tried turning it off and back on again?


    Tuesday, March 13, 2012 10:47 AM

All replies

  • This is exactly the same in 2010, it also uses the 3 log types. You could add all 3 to your template but the problem is it is impossible to get them into the correct order.

    Therefore, you need to create your own custom notification workflow to do this, triggered on the same criteria.

    Something like this snippet can be used to get all 3 log type entries into chronological order:

    EnterpriseManagementObject emoIncident = readerIncident.ElementAt(0);
    
    Guid gRelActionLog = new Guid("a860c62e-e675-b121-f614-e52fcbd9ef2c");
    Guid gRelAnalystComment = new Guid("835a64cd-7d41-10eb-e5e4-365ea2efc2ea");
    Guid gRelUserComment = new Guid("ce423786-16dd-da9c-fb7b-21ab5189e12b");
    ManagementPackClass mpcActionLog = emg.EntityTypes.GetClass(new Guid("dbb6a632-0a7e-cef8-1fc9-405d5cd4d911"));
    ManagementPackClass mpcAnalystComment = emg.EntityTypes.GetClass(new Guid("f14b70f4-878c-c0e1-b5c1-06ca22d05d40"));
    ManagementPackClass mpcUserComment = emg.EntityTypes.GetClass(new Guid("a3d4e16f-5e8a-18ba-9198-d9815194c986"));                   
    IList<EnterpriseManagementObject> logs = new List<EnterpriseManagementObject>();
    
    foreach (EnterpriseManagementRelationshipObject<EnterpriseManagementObject> obj in
            emg.EntityObjects.GetRelationshipObjectsWhereSource<EnterpriseManagementObject>(emoIncident.Id, TraversalDepth.OneLevel, ObjectQueryOptions.Default))
    {
        if (obj.RelationshipId == gRelActionLog ||
            obj.RelationshipId == gRelAnalystComment ||
            obj.RelationshipId == gRelUserComment)
        {  
            logs.Add(obj.TargetObject);                   
        }
    }
    
    if (logs.Count != 0)
    {   
        string sActionLog = "";
    
        foreach (EnterpriseManagementObject emoLog in logs.OrderBy(x => x.TimeAdded))
        {
            string sEnteredDate = "";
            string sTitle = "";
            string sEnteredBy = "";
            string sDescription = "";
            ManagementPackClass mpcLog = null;
            if (emoLog.IsInstanceOf(mpcActionLog)) mpcLog = mpcActionLog;
            else if (emoLog.IsInstanceOf(mpcAnalystComment)) mpcLog = mpcAnalystComment;
            else if (emoLog.IsInstanceOf(mpcUserComment)) mpcLog = mpcUserComment;                  
    
            if (emoLog.IsInstanceOf(mpcActionLog))
            {
                if (emoLog[mpcLog, "Title"].Value != null) sTitle = emoLog[mpcLog, "Title"].Value.ToString();
                if (emoLog[mpcLog, "Description"].Value != null) sDescription = emoLog[mpcLog, "Description"].Value.ToString();
            }
            else if (emoLog.IsInstanceOf(mpcAnalystComment))
            {
                sTitle = "Analyst Comment";
                if (emoLog[mpcLog, "Comment"].Value != null) sDescription = emoLog[mpcLog, "Comment"].Value.ToString();
            }
            else if (emoLog.IsInstanceOf(mpcUserComment))
            {
                sTitle = "End-User Comment";
                if (emoLog[mpcLog, "Comment"].Value != null) sDescription = emoLog[mpcLog, "Comment"].Value.ToString();
            }
            if (emoLog[mpcLog, "EnteredBy"].Value != null) sEnteredBy = emoLog[mpcLog, "EnteredBy"].Value.ToString();
            if (emoLog[mpcLog, "EnteredDate"].Value != null) sEnteredDate = ((DateTime)emoLog[mpcLog, "EnteredDate"].Value).ToLocalTime().ToString();                            
            sActionLog += sTitle + ", " + sEnteredBy + ", " + sEnteredDate + Environment.NewLine;
            sActionLog += sDescription.Trim() + Environment.NewLine + Environment.NewLine;
        }
        Console.WriteLine(sActionLog);
    }



    • Edited by Rob.Ford Monday, March 19, 2012 7:12 PM
    Monday, March 19, 2012 6:20 PM
  • See this under "How we built the solution":
    http://blogs.technet.com/b/servicemanager/archive/2010/05/06/incident-sla-management-in-service-manager.aspx?PageIndex=2

    It provides detailed steps on how to create a workflow activity library in Visual Studio.

    You can use this example to send a custom email from a workflow:

    //Send email notification IDictionary<NotificationRecipientType, IList<string>> NotificationRecipients = new Dictionary<NotificationRecipientType, IList<string>>(); IList<string> Recipients = new List<string>(); Recipients.Add(sAddress); NotificationRecipients.Add(NotificationRecipientType.Primary, Recipients); //Build notification email and send SmtpNotificationMessage nm = new SmtpNotificationMessage(); nm.IsBodyHtml = true; nm.Content = sHTMLHeader + @sHTMLBody + sHTMLFooter; nm.Subject = EmailSubjectText; nm.Encoding = Encoding.UTF8; emg.Notifications.Send(NotificationRecipients, nm, sEmailAddress);

    This was in reply to another question, but it has been deleted...

    • Edited by Rob.Ford Sunday, March 25, 2012 6:13 PM
    Wednesday, March 21, 2012 6:04 PM
  • Did u get it working in scsm 2012?

    Rahul Paul

    Wednesday, May 9, 2012 2:58 AM
  • How, exactly, do I set this up in 2010 and then add the results to a notification?
    Thursday, November 1, 2012 7:43 PM