{"id":453,"date":"2011-09-13T05:11:38","date_gmt":"2011-09-13T04:11:38","guid":{"rendered":"http:\/\/www.stuartroberts.net\/?p=453"},"modified":"2011-09-13T05:11:38","modified_gmt":"2011-09-13T04:11:38","slug":"workflow-activity-part-2","status":"publish","type":"post","link":"http:\/\/www.stuartroberts.net\/index.php\/2011\/09\/13\/workflow-activity-part-2\/","title":{"rendered":"Workflow Activity &#8211; Part 2"},"content":{"rendered":"<p>This is the second part of the custom workflow activity creation tutorial.  For the first part please go <a href=\"http:\/\/www.stuartroberts.net\/index.php\/2011\/09\/13\/workflow-activity-part-1\/\" title=\"Workflow Activity \u2013 Part 1\">here<\/a>.<\/p>\n<p>Now that we have a workflow activity defined, the next step is to add a new project to Visual Studio.<\/p>\n<p><div id=\"attachment_458\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Create-SharePoint-Project.png\"><img aria-describedby=\"caption-attachment-458\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Create-SharePoint-Project-300x206.png\" alt=\"\" title=\"Create SharePoint Project\" width=\"300\" height=\"206\" class=\"size-medium wp-image-458\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Create-SharePoint-Project-300x206.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Create-SharePoint-Project-435x300.png 435w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Create-SharePoint-Project.png 952w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-458\" class=\"wp-caption-text\">Create SharePoint Project<\/p><\/div><br \/>\n<!--more--><br \/>\nNext, add a project reference to the activity project.<\/p>\n<div id=\"attachment_462\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Activity-Project-Reference.png\"><img aria-describedby=\"caption-attachment-462\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Activity-Project-Reference-300x77.png\" alt=\"\" title=\"Activity Project Reference\" width=\"300\" height=\"77\" class=\"size-medium wp-image-462\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Activity-Project-Reference-300x77.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Activity-Project-Reference.png 465w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-462\" class=\"wp-caption-text\">Activity Project Reference<\/p><\/div>\n<p>Now to create the workflow.  Add a <em>new item<\/em> to the project and select a <em>Sequential Workflow<\/em>.<\/p>\n<div id=\"attachment_463\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/New-Sequential-Workflow.png\"><img aria-describedby=\"caption-attachment-463\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/New-Sequential-Workflow-300x206.png\" alt=\"\" title=\"New Sequential Workflow\" width=\"300\" height=\"206\" class=\"size-medium wp-image-463\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/New-Sequential-Workflow-300x206.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/New-Sequential-Workflow-436x300.png 436w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/New-Sequential-Workflow.png 952w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-463\" class=\"wp-caption-text\">New Sequential Workflow<\/p><\/div>\n<p>Give the workflow a name and set it as a list type.<\/p>\n<div id=\"attachment_464\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/New-List-Workflow.png\"><img aria-describedby=\"caption-attachment-464\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/New-List-Workflow-300x237.png\" alt=\"\" title=\"New List Workflow\" width=\"300\" height=\"237\" class=\"size-medium wp-image-464\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/New-List-Workflow-300x237.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/New-List-Workflow-379x300.png 379w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/New-List-Workflow.png 598w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-464\" class=\"wp-caption-text\">New List Workflow<\/p><\/div>\n<p>Next, select the option for associating with libraries and lists.  You can of course opt to not auto associate and this is something I&#8217;d generally do as it allows you to control where and what the workflow is associated to when activating the feature, but that&#8217;s a different topic altogether.<\/p>\n<p>While the new workflow is opened, hover over the <em>toolbox<\/em> pane and you should see the custom activity that was created in the first part of this post.<\/p>\n<div id=\"attachment_465\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Activity-Toolbox.png\"><img aria-describedby=\"caption-attachment-465\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Activity-Toolbox-300x85.png\" alt=\"\" title=\"Activity Toolbox\" width=\"300\" height=\"85\" class=\"size-medium wp-image-465\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Activity-Toolbox-300x85.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Activity-Toolbox-500x141.png 500w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Activity-Toolbox.png 743w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-465\" class=\"wp-caption-text\">Activity Toolbox<\/p><\/div>\n<p>Before adding the activity, add the <em>ApplyActivation<\/em> activity to the designer.<\/p>\n<div id=\"attachment_467\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Apply-Activation-Activity.png\"><img aria-describedby=\"caption-attachment-467\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Apply-Activation-Activity.png\" alt=\"\" title=\"Apply Activation Activity\" width=\"300\" height=\"209\" class=\"size-full wp-image-467\" \/><\/a><p id=\"caption-attachment-467\" class=\"wp-caption-text\">Apply Activation Activity<\/p><\/div>\n<p>To configure the apply activation activity, we first need to create and associate a workflow context property.  To do this, select the activity in the designer, bring up the properties pane and edit the __Context property.<\/p>\n<div id=\"attachment_469\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Edit-Context-Property.png\"><img aria-describedby=\"caption-attachment-469\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Edit-Context-Property-300x138.png\" alt=\"\" title=\"Edit Context Property\" width=\"300\" height=\"138\" class=\"size-medium wp-image-469\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Edit-Context-Property-300x138.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Edit-Context-Property.png 335w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-469\" class=\"wp-caption-text\">Edit Context Property<\/p><\/div>\n<p>Switch to the <em>Bind to a new member tab<\/em> and create a new field.<\/p>\n<p>The difference between a property and a field is that the former creates a dependency property while the latter is a simple .NET property with no such binding.<\/p>\n<p>Do the same for the _WorkflowProperties property, only this time instead of binding to a new member, select the <em>workflowProperties<\/em> item that already exists.<\/p>\n<div id=\"attachment_470\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Bind-Workflow-Properties.png\"><img aria-describedby=\"caption-attachment-470\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Bind-Workflow-Properties-300x228.png\" alt=\"\" title=\"Bind Workflow Properties\" width=\"300\" height=\"228\" class=\"size-medium wp-image-470\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Bind-Workflow-Properties-300x228.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Bind-Workflow-Properties-394x300.png 394w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Bind-Workflow-Properties.png 507w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-470\" class=\"wp-caption-text\">Bind Workflow Properties<\/p><\/div>\n<p>Next, add the custom activity to the workflow, immediately after the <em>ApplyActivation<\/em> activity.<\/p>\n<div id=\"attachment_468\" style=\"width: 147px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Custom-Activity1.png\"><img aria-describedby=\"caption-attachment-468\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Custom-Activity1-137x300.png\" alt=\"\" title=\"Custom Activity\" width=\"137\" height=\"300\" class=\"size-medium wp-image-468\" \/><\/a><p id=\"caption-attachment-468\" class=\"wp-caption-text\">Custom Activity<\/p><\/div>\n<p>Switch to the code behind for the workflow and add the following property.<\/p>\n<pre lang=\"csharp\">\r\npublic SPItemKey ListItemId\r\n{\r\n    get\r\n    {\r\n        return new SPItemKey(workflowProperties.ItemId);\r\n    }\r\n}\r\n<\/pre>\n<p>This will be used to convert the item id for the workflow to an SPItemKey object.<\/p>\n<p>Head back to the designer window and bring up the properties pane for the custom activity.  Here you want to bind __Context to applyActivation1_Context1 (or whatever you called the context field property).  You should also bind the __ListId property to the ListId child property of applyActivation1_Context1.<\/p>\n<div id=\"attachment_473\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Associate-List-Id-Property.png\"><img aria-describedby=\"caption-attachment-473\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Associate-List-Id-Property-300x115.png\" alt=\"\" title=\"Associate List Id Property\" width=\"300\" height=\"115\" class=\"size-medium wp-image-473\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Associate-List-Id-Property-300x115.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Associate-List-Id-Property-500x192.png 500w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Associate-List-Id-Property.png 507w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-473\" class=\"wp-caption-text\">Associate List Id Property<\/p><\/div>\n<p>Next, you should now associate the __ItemId property with the ListItemId property, which we created via code behind.<\/p>\n<div id=\"attachment_475\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Property-Assignments.png\"><img aria-describedby=\"caption-attachment-475\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Property-Assignments-300x53.png\" alt=\"\" title=\"Property Assignments\" width=\"300\" height=\"53\" class=\"size-medium wp-image-475\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Property-Assignments-300x53.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Property-Assignments-500x89.png 500w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Property-Assignments.png 835w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-475\" class=\"wp-caption-text\">Property Assignments<\/p><\/div>\n<p>Lastly, you should enter a valid email address for the EmailTo property.<\/p>\n<div id=\"attachment_476\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Specify-Email-Address.png\"><img aria-describedby=\"caption-attachment-476\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Specify-Email-Address-300x57.png\" alt=\"\" title=\"Specify Email Address\" width=\"300\" height=\"57\" class=\"size-medium wp-image-476\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Specify-Email-Address-300x57.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Specify-Email-Address.png 343w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-476\" class=\"wp-caption-text\">Specify Email Address<\/p><\/div>\n<p>If this were a workflow for a live system this would definitely not be the way to go, you&#8217;d want to dynamically set the value here either from the parent workflow or by retrieving the value from one of the workflow item&#8217;s fields.<\/p>\n<p>We&#8217;re now finished with the workflow.  Next, open the feature editor &#8211; as this is a new project and we only added one workflow there should only be one feature present.  To have SharePoint automatically register this workflow change the <em>receiver assembly<\/em> to <em>Microsoft.Office.Workflow.Feature, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c<\/em> and the <em>receiver class<\/em> to <em>Microsoft.Office.Workflow.Feature.WorkflowFeatureReceiver<\/em>.<\/p>\n<div id=\"attachment_477\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Feature-Receiver.png\"><img aria-describedby=\"caption-attachment-477\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Feature-Receiver-300x67.png\" alt=\"\" title=\"Feature Receiver\" width=\"300\" height=\"67\" class=\"size-medium wp-image-477\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Feature-Receiver-300x67.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Feature-Receiver-1024x229.png 1024w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Feature-Receiver-500x112.png 500w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Feature-Receiver.png 1367w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-477\" class=\"wp-caption-text\">Feature Receiver<\/p><\/div>\n<p>Before we deploy the solution, there is one last thing we need to do and that&#8217;s ensure the assembly for the workflow activity is deployed along with the SharePoint solution.  To do this open the package editor and click on the Advanced link.<\/p>\n<div id=\"attachment_478\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Advanced-Package.png\"><img aria-describedby=\"caption-attachment-478\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Advanced-Package-300x152.png\" alt=\"\" title=\"Advanced Package\" width=\"300\" height=\"152\" class=\"size-medium wp-image-478\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Advanced-Package-300x152.png 300w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Advanced-Package-500x254.png 500w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Advanced-Package.png 752w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-478\" class=\"wp-caption-text\">Advanced Package<\/p><\/div>\n<p>Click the <em>Add<\/em> button and then <em>Add assembly from Project Output&#8230;<\/em>.<\/p>\n<p>From the popup, select the workflow activity project and ensure the deployment target is set to the GAC.<\/p>\n<div id=\"attachment_479\" style=\"width: 282px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Add-Project-Assembly.png\"><img aria-describedby=\"caption-attachment-479\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Add-Project-Assembly-272x300.png\" alt=\"\" title=\"Add Project Assembly\" width=\"272\" height=\"300\" class=\"size-medium wp-image-479\" srcset=\"http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Add-Project-Assembly-272x300.png 272w, http:\/\/www.stuartroberts.net\/wp-content\/uploads\/2011\/09\/Add-Project-Assembly.png 450w\" sizes=\"(max-width: 272px) 100vw, 272px\" \/><\/a><p id=\"caption-attachment-479\" class=\"wp-caption-text\">Add Project Assembly<\/p><\/div>\n<p>Deploy the solution, activate the feature and bob&#8217;s your uncle.  You should now be able to associate the workflow with any list or library and receive an email after creating a new item.  Ensure that your server has an outgoing email server configured and the email address set in the workflow is valid, otherwise you will get errors.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the second part of the custom workflow activity creation tutorial. For the first part please go here. Now that we have a workflow activity defined, the next step is to add a new project to Visual Studio.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[3,82],"tags":[81,6,30],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/plx2I-7j","_links":{"self":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/453"}],"collection":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/comments?post=453"}],"version-history":[{"count":12,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/453\/revisions"}],"predecessor-version":[{"id":1171,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/453\/revisions\/1171"}],"wp:attachment":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/media?parent=453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/categories?post=453"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/tags?post=453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}