Update: All the discussion on this post led me to create a much better solution called Send Email that ships with the Exchange connector. I HIGHLY recommend checking that out as a better alternative to this.
In the MP XML below I've created a notification subscription that will send a notification to the affected user whenever the action log has an analyst comment added to it.
<ManagementPack ContentReadable="true" SchemaVersion="1.1" OriginalSchemaVersion="1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<Name>Action Log Add Relationship Subscription</Name>
<Category ID="Category.ActionLogAddRelationshipSubscriptions.ManagementPack" Value="Console!Microsoft.EnterpriseManagement.ServiceManager.ManagementPack">
<Category ID="Category.ActionLogAddRelationshipSubscriptionRule" Target="ActionLogAddRelationshipSubscriptionRule" Value="Administration!Microsoft.EnterpriseManagement.ServiceManager.Rules.WorkflowSubscriptions" />
<Category ID="ActionLogAddRelationshipAffectedUserNotificationTemplate.Category" Target="ActionLogAddRelationshipAffectedUserNotificationTemplate" Value="Administration!ServiceManager.Console.NotificationManagement.NotificationTemplates.Enumeration" />
<Rule ID="ActionLogAddRelationshipSubscriptionRule" Enabled="true" Target="ServiceManager.IncidentLibrary!System.WorkItem.Incident.WorkflowTarget" ConfirmDelivery="true" Remotable="true" Priority="Normal" DiscardLevel="100">
<DataSource ID="DS" TypeID="Subscriptions!Microsoft.SystemCenter.CmdbInstanceSubscription.DataSourceModule">
<RelationshipSubscription RelType="$MPElement[Name='WorkItem!System.WorkItem.TroubleTicketHasAnalystComment']$" SourceType="$MPElement[Name='WorkItem!System.WorkItem.TroubleTicket']$" TargetType="$MPElement[Name='WorkItem!System.WorkItem.TroubleTicket.AnalystCommentLog']$">
<WriteAction ID="WA" TypeID="Subscriptions!Microsoft.EnterpriseManagement.SystemCenter.Subscription.WindowsWorkflowTaskWriteAction">
<WorkflowParameter Name="InstanceId" Type="guid">$Data/BaseManagedEntityId$</WorkflowParameter>
<WorkflowArrayParameter Name="UserRelationshipIdList" Type="guid">
<WorkflowArrayParameter Name="NotificationTemplateIdList" Type="guid">
<ObjectTemplate ID="ActionLogAddRelationshipAffectedUserNotificationTemplate" TypeID="NotificationsLibrary!System.Notification.Template.SMTP">
<Property Path="$Context/Property[Type='NotificationsLibrary!System.Notification.Template.SMTP']/Subject$"><1033>Action log entry added to $Context/Property[Type='WorkItem!System.WorkItem']/Id$ </1033><2057>Incident ID: [$Context/Property[Type='WorkItem!System.WorkItem']/Id$] has been updated by the analyst</2057></Property>
Created By: $Context/Path[Relationship='WorkItem!System.WorkItemCreatedByUser' TypeConstraint='System!System.User']$?$DisplayName$
</1033><2057>Incident Title: $Context/Property[Type='WorkItem!System.WorkItem']/Title$ &lt;br/&gt;
Assigned To: $Context/Path[Relationship='WorkItem!System.WorkItemAssignedToUser' TypeConstraint='System!System.User']$?$DisplayName$?&lt;br/&gt;
Updated action log entry: &lt;br/&gt;
<LanguagePack ID="ENU" IsDefault="true">
<Name>Action log entry added to action log</Name>
<Name>Notify affected user that action log entry has been added to action log</Name>
Creating relationship subscriptions is actually pretty easy. You just need to follow the pattern above and replace certain configurable parameters with the correct values. I'll explain those here for reference:
First is the Target of the Rule. Unless you know what you are doing, you should probably stick to using a workflow target from among the out of the box list of workflow targets:
Workflow Target Class ID
Workflow Target Class MP
You can get more information on Workflow target from this blog post if you need to do something beyond the above.
Next is to define which RelationshipType you are subscribing to. You can get a list of the relationship type IDs from the database by using the queries provided in this blog post. Each Relationship Type has a Source Class and a Target Class. You can get those from the same blog post using SQL queries.
Next up is to indicate which Related Users you are going to notify. Do this by indicating the relationship type which points from the class that you are notifying about (in this case the Incident class) to a System.Domain.User class. You can get the Relationship Types again using the database query post above.
Last is to indicate which Notification Template you will use. In this case I am using a notification template defined in the same MP.
One last note. You'll see that in this notification template I did something a little fancy. I inserted a insert tag for the Action Log (i.e. TroubleTicketHasAnalystComment relationship type). The relationship between an incident and action log comments is 1:many. So – how do you show that in a notification template? Ideally you would show a list of the action log entries. The same could be true for related configuration items, related work items, etc. In other words anything where there are many items related to the item you are notifying about.
To deal with this we have created a special <Group> tag that can be used in the notification template. When you surround the Insert tag with the Group tag we will iterate through everything in the Group tag and repeat it for each related object.
This is what the Group tag looks like in the notification template properties dialog:
Incident Title: $Context/Property[Type='WorkItem!System.WorkItem']/Title$ <br/>
Assigned To: $Context/Path[Relationship='WorkItem!System.WorkItemAssignedToUser' TypeConstraint='System!System.User']$?$DisplayName$?<br/>
Updated action log entry: <br/>
And this is what it looks like when sent in HTML.
Incident Title: Test Subject Assigned To: Aaron JamesUpdated action log entry:
Note: per this forum thread we had there is a bug in SCSM 2010 which displays the objects in essentially random order. This has been fixed for SP1.
Hi, I would like to ask the same question as Jay. After removing <Group> tag, all comments from Activity log (from particualar Analyst or End-user) still appears under email notification. SCSM SP1.
is there a way to solve this problem using the built-in functionality SCSM 2012? Testing SCSM2012RC we did not find this feature.
Just wanted to check in. Under SCSM 2012 removing the group tag still iterates through all the user comments. Is there a way to change that so only the most recent comment is included? I understand that is supposed to the behavior when you remove the group tags but it's still showing all of them.
Thanks for this great blog.
I need to notify the primary owner when end user add comment from portal, i used the above MP and made some modifications in relationship type, source class and target class but it's not working.
Appreciate your help in this issue.
Thanks in advance.
Hello! This MP has helped me out so much, and your comments have been great.
However, I'm suddenly seeing that Analyst Comments marked as Private are not being sent in the notification! Every e-mail reply I send as the Assigned Analyst is automatically getting flagged as Private and when the Affected User receives the notification the section of the e-mail where the comment(s) should be is blank.
Also, the replies are marked as Private with a square tick mark, and not a check mark. If I uncheck my comments and resend an e-mail reply, the unchecked comments will appear in the e-mail correctly, but the latest reply is again automatically marked private and does not get sent out.
Is there a way to stop these replies from being marked as private in the first place? It seems they are inheriting this from somewhere, but I can't figure out where. Also, I thought it would send out the analyst comments, private or not?
Thanks for your help!
After much frustrated trial and error, I have discovered that it is the <Group> tags breaking this. If I remove them, the comments come in fine, but ugly and and out of date. If I re-add them, they do not show up at all, unless they are not marked as Private.
I am using these <Group> tags in another notification and they work perfectly. I have copied and pasted the HTML code from above--am I missing something?
Im trying to modify this for a Service Request. Any tips?