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 = "email@example.com,firstname.lastname@example.org" 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