How to use the EmailNotificationActivity in a custom workflow

I just put together a workflow prototype for a project: when the membership of certain Criteria-based groups changes the groups’ Owners should be notified. This gave me an opportunity to use the EmailNotificationActivity inside a custom Workflow for the first time. As usual I found the official documentation to be somewhat … thin.

Implementing the Activity

As is the case with most of these FIM activity components, you need to set the stage with some code first.

Inside my code activity I have to set the following two properties:

  • the To field – a comma separated list of email addresses, and
  • the Email Template, which must exist in the FIM Portal, and is identified by its ResourceID.

The following example is the most simple as I’ve just hardcoded the values.

Me.emailNotificationActivity_To1 = "jack.black@somecompany.com,jack.white@somecompany.com"
Me.emailNotificationActivity_EmailTemplate1 = New System.Guid("727756dc-92b3-4861-8cab-4ab81ca28a3d")

Of course you won’t be hardcoding values in your code like this – where you get them from I’ll leave up to you.

In my case I get the email addresses by looping through the group’s Owners. The email template I’m getting through the completely inelegant approach of hardcoding the template’s ResourceID in my Workflow configuration. If anyone can tell me how to get an Identity Picker into the Workflow UI I’d be much oblidged!

Fleshing out your email with WorkflowData

The other thing I found is that I needed to use WorkflowData parameters to improve the content of my notification email.

For example, you don’t want to send an email to someone saying “A group has changed” – that’s not very informative! You want to send them “Group ‘Dark Chocolate Fans’ has changed; Carol Wapshere has been added to group ‘Dark Chocolate Fans’ “.

In my prototype I could get the name of the of the user whose membership had changed through the //Target construct, but I was reading the changed group (or groups) from the Request object. This meant that the Group Name was something I would only have access to while the workflow was running.

I added a string property to the Workflow UI where the user can enter a WorkflowData parameter name:

I then made sure that I was using the same parameter name in my Email Template:

And finally, I added this code to the initNotification activity, after setting the To and Template parameters. Note that WFParamName is the UI Property I defined. And the object readGroup_Resource1 is the result of an earlier ReadResourceActivity where I looked up the group object.

            '' Return group name in WorkflowData to use in email template
            Dim containingWorkflow As SequentialWorkflow = Nothing
            If Not SequentialWorkflow.TryGetContainingWorkflow(Me, containingWorkflow) Then
                Throw New InvalidOperationException("Unable to get Containing Workflow")
            End If
            Try
                If containingWorkflow.WorkflowDictionary.ContainsKey(Me.WFParamName) Then
                    containingWorkflow.WorkflowDictionary.Remove(Me.WFParamName)
                End If
                containingWorkflow.WorkflowDictionary.Add(Me.WFParamName, readGroup_Resource1("DisplayName"))
            Catch
                Throw New InvalidOperationException("Unable to update WorkflowData parameter " & Me.WFParamName)
            End Try

About: Carol

I've been doing IT for 30 years, and IdM for 15. I live in Australia and build IdM solutions based on Microsoft Identity Manager. I also play the violin, but that doesn't help much with the IdM solutions.


4 thoughts on “How to use the EmailNotificationActivity in a custom workflow”

  1. Carol.

    you can’t use IdentityPicker web control ’cause it was declared as an internal class.
    I talked to the product group and it won’t be changed in R2.

    I’m curious about the MPR you’ve created for triggering your workflow. the ComputedMember attribute changes will not fire up any workflows by design. So I wanna be wrong, but you won’t get what you want…

  2. well… it’s doable, but will require 1 more custom attribute bound to the group object.

  3. Firstly – no Identity Picker on the Workflow UI? That’s annoying – another thing for us to keep the pressure on about. Did you already raise it on connect?

    With the MPR – we’re actually doing this via a custom MemberOf attribute on the person object. The group rule is then very simply “if MemberOf contains…” So the WF is triggered by a change to the MemberOf attribute.

  4. nope, it’s not listed as a bug on the connect site.
    I hoped to get an answer why it was made ‘internal class’ but had no luck with it.

Leave a Reply

Your email address will not be published. Required fields are marked *


*