Custom Notification workflow on activity assignment or reassignment

Custom Notification workflow on activity assignment or reassignment

  • Comments 11
  • Likes

This blog posts demonstrates how to configure a notification workflow in Service Manager that sends out notifications on assignment or reassignment of an Activity.

1.       Steps for creating this custom workflow:

1.       Create a new XML file – Name it:  Custom.ActivityWorkflows.xml

a.       The name of the file should match the mp. If you decide to name your management pack something different the file name will have to match

2.       Copy and paste the complete XML provided in section 2.

3.       Save the File

4.       Last Step is to Import the management pack

a.       Service Manager Console

b.      Open Go to Administration -> Management Packs

c.       Click on “Import” in the task pane

d.      Click “Add” in the MP Import screen

e.      Select the management pack file that you created

f.        Click Import             

g.       If you get errors, please check again your MP against the XML I have provided.

5.       Verification

a.       Open Service Manager Console

b.      Go to Administration->Workflows->Status

c.       You should see “Assigned to user added to activity” in the view pane as shown below

Activity assigned to user workflow

d.       Assign an activity to a user and make sure the mail is sent

2.       Complete XML of the management pack:                   

Please note that this is for the RC build.

<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">

  <Manifest>

    <Identity>

      <ID>Custom.ActivityWorkflows</ID>

      <Version>7.0.5813.0</Version>

    </Identity>

    <Name>Custom Activity Workflows</Name>

    <References>

      <Reference Alias="WorkItem">

        <ID>System.WorkItem.Library</ID>

        <Version>7.0.5813.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

      <Reference Alias="ActivityManagement">

        <ID>ServiceManager.ActivityManagement.Library</ID>

        <Version>7.0.5813.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

      <Reference Alias="EnterpriseManagement1">

        <ID>Microsoft.EnterpriseManagement.ServiceManager.UI.Administration</ID>

        <Version>7.0.5813.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

      <Reference Alias="EnterpriseManagement">

        <ID>Microsoft.EnterpriseManagement.ServiceManager.UI.Console</ID>

        <Version>7.0.5813.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

      <Reference Alias="System">

        <ID>System.Library</ID>

        <Version>7.0.5813.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

      <Reference Alias="CoreActivity">

        <ID>System.WorkItem.Activity.Library</ID>

        <Version>7.0.5813.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

      <Reference Alias="SystemCenter">

        <ID>Microsoft.SystemCenter.Subscriptions</ID>

        <Version>7.0.5813.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

      <Reference Alias="CustomSystem_Notifications_Library">

        <ID>System.Notifications.Library</ID>

        <Version>7.0.5813.0</Version>

        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>

      </Reference>

    </References>

  </Manifest>

  <Categories>

    <Category ID="Category.Custom.ActivityWorkflows.ManagementPack" Value="EnterpriseManagement!Microsoft.EnterpriseManagement.ServiceManager.ManagementPack">

      <ManagementPackName>Custom.ActivityWorkflows</ManagementPackName>

      <ManagementPackVersion>7.0.5813.0</ManagementPackVersion>

    </Category>

    <Category ID="Category.ActivityAssignedToUserAddRule" Target="ActivityAssignedToUserAddRule" Value="EnterpriseManagement1!Microsoft.EnterpriseManagement.ServiceManager.Rules.WorkflowSubscriptions" />

    <Category ID="ServiceManager.Console.NotificationManagement.NotificationTemplates.ActivityAssignedToUserNotificationTemplate.Category" Target="ActivityAssignedToUserNotificationTemplate" Value="EnterpriseManagement1!ServiceManager.Console.NotificationManagement.NotificationTemplates.Enumeration" />

  </Categories>

  <Monitoring>

    <Rules>

      <Rule ID="ActivityAssignedToUserAddRule" Enabled="true" Target="ActivityManagement!System.WorkItem.Activity.WorkflowTarget" ConfirmDelivery="true" Remotable="true" Priority="Normal" DiscardLevel="100">

        <Category>System</Category>

        <DataSources>

          <DataSource ID="DS" TypeID="SystemCenter!Microsoft.SystemCenter.CmdbInstanceSubscription.DataSourceModule">

            <Subscription>

              <RelationshipSubscription RelType="$MPElement[Name='WorkItem!System.WorkItemAssignedToUser']$" SourceType="$MPElement[Name='CoreActivity!System.WorkItem.Activity']$" TargetType="$MPElement[Name='System!System.Domain.User']$">

                <AddRelationship />

              </RelationshipSubscription>

              <PollingIntervalInSeconds>30</PollingIntervalInSeconds>

              <BatchSize>100</BatchSize>

            </Subscription>

          </DataSource>

        </DataSources>

        <WriteActions>

          <WriteAction ID="WA" TypeID="SystemCenter!Microsoft.EnterpriseManagement.SystemCenter.Subscription.WindowsWorkflowTaskWriteAction">

            <Subscription>

              <EnableBatchProcessing>false</EnableBatchProcessing>

              <WindowsWorkflowConfiguration>

                <AssemblyName>Microsoft.EnterpriseManagement.WorkflowFoundation</AssemblyName>

                <WorkflowTypeName>Microsoft.EnterpriseManagement.WorkflowFoundation.ConfigurationWorkflow</WorkflowTypeName>

                <WorkflowParameters>

                  <WorkflowParameter Name="InstanceId" Type="guid">$Data/BaseManagedEntityId$</WorkflowParameter>

                  <WorkflowArrayParameter Name="UserRelationshipIdList" Type="guid">

                    <Item>$MPElement[Name='WorkItem!System.WorkItemAssignedToUser']$</Item>

                  </WorkflowArrayParameter>

                  <WorkflowArrayParameter Name="NotificationTemplateIdList" Type="guid">

                    <Item>$MPElement[Name='ActivityAssignedToUserNotificationTemplate']$</Item>

                  </WorkflowArrayParameter>

                </WorkflowParameters>

                <RetryExceptions />

                <RetryDelaySeconds>60</RetryDelaySeconds>

                <MaximumRunningTimeSeconds>7200</MaximumRunningTimeSeconds>

              </WindowsWorkflowConfiguration>

            </Subscription>

          </WriteAction>

        </WriteActions>

      </Rule>

    </Rules>

  </Monitoring>

  <Templates>

    <ObjectTemplate ID="ActivityAssignedToUserNotificationTemplate" TypeID="CustomSystem_Notifications_Library!System.Notification.Template.SMTP">

      <Property Path="$Context/Property[Type='CustomSystem_Notifications_Library!System.Notification.Template.SMTP']/Subject$">&lt;1033&gt;Activity $Context/Property[Type='WorkItem!System.WorkItem']/Id$ is assigned to you&lt;/1033&gt;</Property>

      <Property Path="$Context/Property[Type='CustomSystem_Notifications_Library!System.Notification.Template.SMTP']/Priority$">2</Property>

      <Property Path="$Context/Property[Type='CustomSystem_Notifications_Library!System.Notification.Template.SMTP']/IsBodyHtml$">False</Property>

      <Property Path="$Context/Property[Type='CustomSystem_Notifications_Library!System.Notification.Template']/Content$">&lt;1033&gt;Details:

 

Title: $Context/Property[Type='WorkItem!System.WorkItem']/Title$

Description: $Context/Property[Type='WorkItem!System.WorkItem']/Description$

Created By: $Context/Path[Relationship='WorkItem!System.WorkItemCreatedByUser' TypeConstraint='System!System.User']$?$DisplayName$?

&lt;/1033&gt;</Property>

      <Property Path="$Context/Property[Type='CustomSystem_Notifications_Library!System.Notification.Template']/Encoding$">utf-8</Property>

      <Property Path="$Context/Property[Type='CustomSystem_Notifications_Library!System.Notification.Template']/SeedClass$">System.WorkItem.Activity$3fc62adf-d590-ed19-587e-e029aecb738d</Property>

      <Property Path="$Context/Property[Type='CustomSystem_Notifications_Library!System.Notification.Template']/Protocol$">SMTP</Property>

    </ObjectTemplate>

  </Templates>

  <LanguagePacks>

    <LanguagePack ID="ENU" IsDefault="true">

      <DisplayStrings>

        <DisplayString ElementID="Custom.ActivityWorkflows">

          <Name>Custom Activity Workflows</Name>

        </DisplayString>

        <DisplayString ElementID="ActivityAssignedToUserAddRule">

          <Name>Assigned to user added to activity</Name>

        </DisplayString>

        <DisplayString ElementID="ActivityAssignedToUserNotificationTemplate">

          <Name>Activity assigned to user template</Name>

        </DisplayString>

      </DisplayStrings>

    </LanguagePack>

  </LanguagePacks>

</ManagementPack>

 

3.       Here is some explanation of some of the sections of the Management pack to better understand the “how”

This section requires advanced understanding of SM and is not needed to achieve the goal of sending proper notification on Activity assignment. You should skip this section is you are only interested in the “how to get it to work”.

1.        Manifest Section

a.       The references section identifies the Management Pack and lists the dependencies for this management pack

b.      Aliases defined for these references make it easier to refer to these management packs in the subsequent sections

2.        Categories section

a.       This enables the Workflow to appear in the Service Manager Console UI (Administration->Workflow->Status node)

b.      This allows you to either enable or disable the workflow from the Console UI, thus avoiding having to go and edit (or delete) the management pack each time you want to disable the workflow

3.        ObjectTemplate

a.       This contains an activity notification template. I have added this in this MP to provide a notification template for Activity.

b.      UI provides easy editing of the template content: Go to Administration->Notifications->Templates, select “Activity assigned to user template” and click on the “Properties”

Activity Notification Template

4.        Monitoring Section

a.       In the Monitoring section we define the Rules.  Each rule is generally comprised of a DataSource and WriteAction

b.      DataSource defines discovery of the instances based on certain criteria.

                                   i.      In this case we want to discover any Activity for which the “Assigned to” user is changed.

                                  ii.      “Assigned To” user is a relationship on the Workitem (base class for Activity) – So whenever the assignment is changed the existing relationship is deleted and a new relationship is added

                                iii.      The criteria below discovers all instances of Activity for which a “AssignedTo” Relationship was added

<RelationshipSubscription

RelType="$MPElement[Name='WorkItem!System.WorkItemAssignedToUser']$" Name of the relationship

SourceType="$MPElement[Name='CoreActivity!System.WorkItem.Activity']$" Type of object (restrict it to Activity and derived classes)

TargetType="$MPElement[Name='System!System.Domain.User']$"> Type of object (restrict it to Domain User and derived classes)

                <AddRelationship /> When a new instance of relationship is added

              </RelationshipSubscription>

c.       WriteAction defines the “action” you want to perform on each instance that was discovered by the rule

                                   i.      Write Action is generally associated with an Activity/Task.

                                  ii.      In this case we are re-using a workflow that is used by “Change Request Event Workflow Configuration” and “Activity Event Workflow Configuration”.

                                iii.      Note:  This is not a published activity in our Authoring library, so the parameters potentially could change in future

<AssemblyName>Microsoft.EnterpriseManagement.WorkflowFoundation</AssemblyName>                <WorkflowTypeName>Microsoft.EnterpriseManagement.WorkflowFoundation.ConfigurationWorkflow</WorkflowTypeName>

                                iv.      The workflow takes the following parameters.

1.       InstanceId – The identifier for your relationship instance. This is required.

<WorkflowParameter Name="InstanceId" Type="guid">$Data/BaseManagedEntityId$</WorkflowParameter>

2.       For notifications you need the following parameters.

   <WorkflowArrayParameter Name="UserRelationshipIdList" Type="guid">                           <Item>$MPElement[Name='WorkItem!System.WorkItemAssignedToUser']$</Item>

   </WorkflowArrayParameter>

 

   <WorkflowArrayParameter Name="NotificationTemplateIdList" Type="guid">

<Item>$MPElement[Name='ActivityAssignedToUserNotificationTemplate']$</Item>

   </WorkflowArrayParameter>

 

This is an array parameter. So you can specify multiple relationships and notification templates.

The order of the items will determine the template used for the relationship. The first notification template will be used for the first relationship, the second template will be used for the second relationship and so on.. The number of items in both array parameters above should be the same.

 If your relationship or notification template is an a different unsealed mp you will have to put the guid Id with the Item tag above.

 In order to get the GUID for your own template from the DB you can use a simple query. "select Objecttemplateid from ObjectTemplate where ObjectTemplateName='<name of the template>'

3.       For applying template the workflow takes the following parameter.

   <WorkflowParameter Name="TemplateId" Type="guid"> MPElement[Name='<Name of template>']</WorkflowParameter>

You can also use this workflow to apply a template to the activity. The template is applied before the mail is sent.

5.        Language Pack section:

a.       This enables display of user friendly names in the UI.

b.      You should also review the blog for details regarding localizing the UI

 

4.       How to perform a similar task for a different type:

You can use the above workflow for other types as well.

For example, if you want do similar task for a Change Request assignment change.

You need to create or use an existing change request notification template and replace references to System.WorkItem.Activity with System.WorkItem.ChangeRequest. You will have to add a reference to the System.WorkItem.ChangeRequest.Library library in the Manifest->References section and use the correct alias when refering to the type.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Hi

    Has anyone tested this on RTM?

    Cheers

    Graham

  • Good afternoon,

    When I attempt to use this workflow, I receive the following exception:

    Cannot resolve identifier WIGroup!System.WorkItem in the context of management pack Custom.ActivityWorkflows. Unknown alias: WIGroup

    This occurs at the following states in the workflow:

    sendNotificationsActivity

    notifyIterator

    ConfigurationWorkflow

    sequenceActivitity

    notify

    ifElseActivity2

    Thoughts/suggestions?  I would like to have an email sent to Assigned To users of Activities when it changes.

  • Hi Amit,

    I am stuck. Can you clearify which part I will change on your xml exactly? I have created a template called "Manual Activity Template" saved in ServiceManager.ActivityManagement.Configuration.xml. So which part do I need to change?

  • Hello

    Thanks for the usefull article

    I have SCSM SP1

    I have tried to use it as is , it is imported successfully but not sending email , and it is showing no warning or error in the status of workflow

    I have deleted and edit the version to match the SP1 version but it doesn't work even

    Regards,

  • Hello, I have SCSM 2010 SP1 + CU1.

    What I must change in Custom.ActivityWorkflows.xml to make it work on my version ? (this xml in blog is created for SCSM 2010 RC)

    Thanks in advance.

    Best regards,

    Dubravko

  • So does this work in SCSM 2010 Sp1 or not? Anybody getting it to work?

  • I have a working solution for SCSM 2010 SP1 CU1 that covers notifications for all 4 work items here:

    scsmsource.blogspot.com/.../work-item-assignmentreassignment.html

  • Can anyone confirm the above approach works for SCSM 2012 SP1 ?

  • @Wyatt Wong

    If we are talking about _approach_, yes, it works fine for SCSM 2012 SP1 UR2.

    _Approach_ means in a few words:

    - using of "RelationshipSubscription" to track "WorkItemAssignedToUser" property

    - manual editing and troubleshooting of management pack including update for all names and aliases

    - own workflow that could combine different triggers to fire notification process (e.g. custom extended Activity class to keep flags related to assignment or re-assignment)

    BR,

    Anatoliy

  • Hello!

    I'm using this on SCSM 2012 SP1 and it's working fine!

    Is it possible to add a new criteria to just send the notification for assignment change IF the workitem is active?

    Regards,

  • Hi Amit,

    I'm looking to add a condition that indicates not to send the notification when the activity is in pending status. Is this something I'd be able to paste into the xml mp?

    Regards,

    SL