{"id":1638,"date":"2011-08-22T05:06:04","date_gmt":"2011-08-22T05:06:04","guid":{"rendered":"https:\/\/www.wapshere.com\/missmiis\/?p=1638"},"modified":"2011-08-22T05:06:04","modified_gmt":"2011-08-22T05:06:04","slug":"how-to-use-the-emailnotificationactivity-in-a-custom-workflow","status":"publish","type":"post","link":"https:\/\/www.wapshere.com\/missmiis\/how-to-use-the-emailnotificationactivity-in-a-custom-workflow","title":{"rendered":"How to use the EmailNotificationActivity in a custom workflow"},"content":{"rendered":"<p>I just put together a workflow prototype for a project: when the membership of certain Criteria-based groups changes the groups&#8217; 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 <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.resourcemanagement.workflow.activities.emailnotificationactivity.aspx\">official documentation<\/a> to be somewhat &#8230; thin.<\/p>\n<p><!--more--><\/p>\n<h3>Implementing the Activity<\/h3>\n<p>As is the case with most of these FIM activity components, you need to set the stage with\u00c2\u00a0some code\u00c2\u00a0first.<\/p>\n<p><a href=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/08\/EmailNotificationActivity.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1639\" title=\"EmailNotificationActivity\" src=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/08\/EmailNotificationActivity.jpg\" alt=\"\" width=\"164\" height=\"132\" \/><\/a><\/p>\n<p>Inside my code activity I have to set the following two properties:<\/p>\n<ul>\n<li>the To field &#8211; a comma separated list of email addresses, and<\/li>\n<li>the Email Template, which must exist in the FIM Portal, and is identified by its ResourceID.<\/li>\n<\/ul>\n<p>The following example is the most simple as\u00c2\u00a0I&#8217;ve just hardcoded the values.<\/p>\n<pre>Me.emailNotificationActivity_To1 = \"jack.black@somecompany.com,jack.white@somecompany.com\"\r\nMe.emailNotificationActivity_EmailTemplate1 = New System.Guid(\"727756dc-92b3-4861-8cab-4ab81ca28a3d\")<\/pre>\n<p>Of course you won&#8217;t be hardcoding values in your code like this &#8211; where you get them from I&#8217;ll leave up to you.<\/p>\n<p>In my case I get the email addresses by looping through the group&#8217;s Owners. The email template I&#8217;m getting through the completely inelegant approach of hardcoding the template&#8217;s ResourceID in my Workflow configuration. <strong><em>If anyone can tell me how to get an Identity Picker into the Workflow UI I&#8217;d be much oblidged!<\/em><\/strong><\/p>\n<p><strong><a href=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/08\/EmailNotificationActivityUI.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1640\" title=\"EmailNotificationActivityUI\" src=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/08\/EmailNotificationActivityUI.jpg\" alt=\"\" width=\"456\" height=\"62\" srcset=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/08\/EmailNotificationActivityUI.jpg 456w, https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/08\/EmailNotificationActivityUI-300x40.jpg 300w\" sizes=\"auto, (max-width: 456px) 100vw, 456px\" \/><\/a><\/strong><\/p>\n<h3>Fleshing out your email with WorkflowData<\/h3>\n<p>The other thing I found is that I needed to use WorkflowData parameters to improve the content of my notification email.<\/p>\n<p>For example, you don&#8217;t want to send an email to someone saying &#8220;A group has changed&#8221; &#8211; that&#8217;s not very informative! You want to send them &#8220;Group\u00c2\u00a0&#8216;Dark Chocolate Fans&#8217;\u00c2\u00a0has changed; Carol Wapshere has been added to group &#8216;Dark Chocolate Fans&#8217; &#8220;.<\/p>\n<p>In my prototype I could get the name of the\u00c2\u00a0of 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.<\/p>\n<p>I added a string property to the Workflow UI where the user can enter a WorkflowData parameter name:<\/p>\n<p><a href=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/08\/EmailNotificationActivityUI-wfdata.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1641\" title=\"EmailNotificationActivityUI-wfdata\" src=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/08\/EmailNotificationActivityUI-wfdata.jpg\" alt=\"\" width=\"282\" height=\"31\" \/><\/a><\/p>\n<p>I then made sure that I was using the same parameter name in my Email Template:<\/p>\n<p><a href=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/08\/EmailNotificationActivity-EmailTmpl.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1642\" title=\"EmailNotificationActivity-EmailTmpl\" src=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/08\/EmailNotificationActivity-EmailTmpl.jpg\" alt=\"\" width=\"517\" height=\"236\" srcset=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/08\/EmailNotificationActivity-EmailTmpl.jpg 517w, https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/08\/EmailNotificationActivity-EmailTmpl-300x136.jpg 300w\" sizes=\"auto, (max-width: 517px) 100vw, 517px\" \/><\/a><\/p>\n<p>And finally, I added this code to the initNotification activity, after setting the To and Template parameters. Note that <strong>WFParamName<\/strong> is the UI Property I defined. And the object <strong>readGroup_Resource1<\/strong> is the result of an earlier <a href=\"https:\/\/www.wapshere.com\/missmiis\/how-to-use-the-fim-readresourceactivity-in-vb-net\">ReadResourceActivity<\/a> where I looked up the group object.<\/p>\n<pre>            '' Return group name in WorkflowData to use in email template\r\n            Dim containingWorkflow As SequentialWorkflow = Nothing\r\n            If Not SequentialWorkflow.TryGetContainingWorkflow(Me, containingWorkflow) Then\r\n                Throw New InvalidOperationException(\"Unable to get Containing Workflow\")\r\n            End If\r\n            Try\r\n                If containingWorkflow.WorkflowDictionary.ContainsKey(Me.WFParamName) Then\r\n                    containingWorkflow.WorkflowDictionary.Remove(Me.WFParamName)\r\n                End If\r\n                containingWorkflow.WorkflowDictionary.Add(Me.WFParamName, readGroup_Resource1(\"DisplayName\"))\r\n            Catch\r\n                Throw New InvalidOperationException(\"Unable to update WorkflowData parameter \" &amp; Me.WFParamName)\r\n            End Try<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I just put together a workflow prototype for a project: when the membership of certain Criteria-based groups changes the groups&#8217; 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 &#8230; thin.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[52,42,30,45],"tags":[],"class_list":["post-1638","post","type-post","status-publish","format-standard","hentry","category-email-template","category-fim-2010","category-vbnet","category-workflow"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pkp1o-qq","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/1638","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/comments?post=1638"}],"version-history":[{"count":8,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/1638\/revisions"}],"predecessor-version":[{"id":1650,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/1638\/revisions\/1650"}],"wp:attachment":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/media?parent=1638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/categories?post=1638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/tags?post=1638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}