<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Workflows Archives - Blog IT</title>
	<atom:link href="https://blogit.create.pt/category/workflows/feed/" rel="self" type="application/rss+xml" />
	<link>https://blogit.create.pt/category/workflows/</link>
	<description>Create IT blogger community</description>
	<lastBuildDate>Wed, 11 Sep 2019 20:40:32 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>SharePoint 2007 Workflow &#8211; Using the OnWorkflowItemDeleted activity</title>
		<link>https://blogit.create.pt/miguelisidoro/2009/02/07/sharepoint-2007-workflow-using-the-onworkflowitemdeleted-activity/</link>
					<comments>https://blogit.create.pt/miguelisidoro/2009/02/07/sharepoint-2007-workflow-using-the-onworkflowitemdeleted-activity/#respond</comments>
		
		<dc:creator><![CDATA[Miguel Isidoro]]></dc:creator>
		<pubDate>Sat, 07 Feb 2009 16:03:48 +0000</pubDate>
				<category><![CDATA[Windows Workflow Foundation]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Workflows]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[WSS]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/miguelisidoro/?p=71</guid>

					<description><![CDATA[<p>Introduction One of the most exciting features included in SharePoint 2007 is workflow support and the possibility of developing our own custom workflows (for more information about workflow development in the SharePoint 2007 platform please click here). While it is possible to develop workflows to automate a series of activities without any human intervention, the [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/miguelisidoro/2009/02/07/sharepoint-2007-workflow-using-the-onworkflowitemdeleted-activity/">SharePoint 2007 Workflow &#8211; Using the OnWorkflowItemDeleted activity</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h5>Introduction</h5>
<p>One of the most exciting features included in SharePoint 2007 is workflow support and the possibility of developing our own custom workflows (for more information about workflow development in the SharePoint 2007 platform please click <a href="http://msdn.microsoft.com/en-us/library/ms549489.aspx" target="_blank">here</a>). </p>
<p>While it is possible to develop workflows to automate a series of activities without any human intervention, the full power of workflows in the SharePoint platform can only be achieved with human-oriented workflows. These workflows are characterized by creating and assigning tasks to users that must complete them in order to fulfill the purpose of the workflow. Some examples of out of the box human-oriented workflows that are included with MOSS 2007 are Approval, Collect Feedback and Issue Tracking.</p>
<p>In the SharePoint world, the most common usage of human-oriented workflows is in the context of document libraries, to perform some work when a new document is uploaded into a document library. Typically, in such scenario, tasks are created and assigned to users throughout the workflow lifetime that will complete them until the workflow purpose has been fulfilled. Having the workflow goal to be achieved is the desired and most common scenario, but unexpected actions may occur before the end of the workflow such as a user to delete the document. The following example will show you how to handle this situation in a custom workflow by using the OnWorkflowItemDeleted activity.</p>
<h5>Example</h5>
<p>The OnWorkflowItemDeleted activity can be used within a custom workflow to handle an item deletion in any SharePoint list. In this example, this activity will be used to delete all uncompleted tasks associated with the deleted item. After dragging and dropping the OnWorkflowItemDeleted activity into the workflow designer, the Invoke property must be set to the event handler that will perform the work. </p>
<p>For the purpose of this example, please consider the simple approval workflow in the following image:</p>
<p><img decoding="async" src="http://pic90.picturetrail.com/VOL2147/10903553/19399056/354040008.jpg"> </p>
<p>In this workflow, a parallel activity with two branches is used. One contains the main workflow logic while the other contains a OnWorkflowItemDeleted activity that will handle the item deletion. The Invoke event property was set to be handled by an event handler method called OnWorkflowItemDeleted_Invoked. Let&#8217;s take a look at the code:</p>
<pre class="code"><span style="color: blue">public sealed partial class </span><span style="color: #2b91af">ApprovalWorkflow </span>: SequentialWorkflowActivity
{
    <span style="color: gray">/// &lt;summary&gt;
    /// </span><span style="color: green">Handles the workflow item deleted event.
    </span><span style="color: gray">/// &lt;/summary&gt;
    /// &lt;param name=&quot;sender&quot;&gt;&lt;/param&gt;
    /// &lt;param name=&quot;e&quot;&gt;&lt;/param&gt;
    </span><span style="color: blue">private void </span>OnWorkflowItemDeleted_Invoked(<span style="color: blue">object </span>sender, ExternalDataEventArgs e)
    {
        <span style="color: green">//delete uncompleted tasks when 
        //an item is deleted
        </span>SPWorkflow workflowInstance = 
            workflowProperties.Workflow;
        SPWorkflowTaskCollection taskCollection = 
            GetWorkflowTasks(workflowInstance);
        <span style="color: blue">for </span>(<span style="color: blue">int </span>i = taskCollection.Count; i &gt; 0; i--)
        {
            SPWorkflowTask task = 
                taskCollection[i - 1];
            <span style="color: blue">using </span>(SPWeb web = 
                workflowProperties.Web)
            {
                <span style="color: blue">if </span>(task[SPBuiltInFieldId.TaskStatus]
                    .ToString() != SPResource.GetString
                    (<span style="color: blue">new </span><span style="color: #2b91af">CultureInfo</span>((<span style="color: blue">int</span>)web.Language, <span style="color: blue">false</span>),
                    <span style="color: #a31515">&quot;WorkflowTaskStatusComplete&quot;</span>, <span style="color: blue">new object</span>[0]))
                {
                    task.Delete();
                }
            }
        }
    }

    <span style="color: gray">/// &lt;summary&gt;
    /// </span><span style="color: green">Reads the workflow tasks. This method 
    </span><span style="color: gray">/// </span><span style="color: green">is implemented because the Tasks property
    </span><span style="color: gray">/// </span><span style="color: green">of the SPWorkflow instance takes a 
    </span><span style="color: gray">/// </span><span style="color: green">while to be populated.
    </span><span style="color: gray">/// &lt;/summary&gt;
    </span><span style="color: blue">public static </span>SPWorkflowTaskCollection 
        GetWorkflowTasks(SPWorkflow workflowInstance)
    {
        SPWorkflowTaskCollection taskCollection = <span style="color: blue">null</span>;
        <span style="color: blue">bool </span>tasksPopulated = <span style="color: blue">false</span>;
        <span style="color: blue">while </span>(!tasksPopulated)
        {
            <span style="color: blue">try
            </span>{
                taskCollection = workflowInstance.Tasks;
                tasksPopulated = <span style="color: blue">true</span>;
            }
            <span style="color: blue">catch </span>{ }
        }

        <span style="color: blue">return </span>taskCollection;
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>In the previous example, the following actions are being performed:</p>
<ul>
<li>In the OnWorkflowItemDeleted_Invoked event handler, the workflow instance task collection is obtained by calling the GetWorkflowTasks method;</li>
<li>The task collection is iterated and the each task status is checked to verify if it is still uncompleted;</li>
<li>If so, the task is deleted.</li>
</ul>
<p>The post <a href="https://blogit.create.pt/miguelisidoro/2009/02/07/sharepoint-2007-workflow-using-the-onworkflowitemdeleted-activity/">SharePoint 2007 Workflow &#8211; Using the OnWorkflowItemDeleted activity</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/miguelisidoro/2009/02/07/sharepoint-2007-workflow-using-the-onworkflowitemdeleted-activity/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SharePoint 2007 &#8211; Checking if a Workflow Instance is Completed</title>
		<link>https://blogit.create.pt/miguelisidoro/2008/10/25/sharepoint-2007-checking-if-a-workflow-instance-is-completed/</link>
					<comments>https://blogit.create.pt/miguelisidoro/2008/10/25/sharepoint-2007-checking-if-a-workflow-instance-is-completed/#respond</comments>
		
		<dc:creator><![CDATA[Miguel Isidoro]]></dc:creator>
		<pubDate>Sat, 25 Oct 2008 12:31:59 +0000</pubDate>
				<category><![CDATA[Windows Workflow Foundation]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Workflows]]></category>
		<category><![CDATA[SharePoint]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/miguelisidoro/?p=111</guid>

					<description><![CDATA[<p>Introduction This blog post will show you how to check if a certain workflow instance is completed in a SharePoint list. In this example, let&#8217;s assume that the default &#8220;Documents&#8221; document library in a team site is configured with a Collect Feedback workflow and that a new instance is started every time a new document [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/miguelisidoro/2008/10/25/sharepoint-2007-checking-if-a-workflow-instance-is-completed/">SharePoint 2007 &#8211; Checking if a Workflow Instance is Completed</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1>Introduction</h1>
<p>This blog post will show you how to check if a certain workflow instance is completed in a SharePoint list. In this example, let&#8217;s assume that the default &#8220;Documents&#8221; document library in a team site is configured with a Collect Feedback workflow and that a new instance is started every time a new document is added to the library. The workflow is configured with 2 reviewers. My purpose is to start a custom workflow (associated with a custom workflow) on each document every time all reviewers have reviewed them, i.e., every time a Collect Feedback workflow instance is completed.</p>
<h1>Example</h1>
<p>The following example shows how the previously described scenario can be implemented. One first note is that when a workflow instance gets completed on a list item (thus changing the workflow status of the item), the item is not updated. This means that the obvious solution that would be to have an event handler running on the document library to detect the completion of the workflow for each document can&#8217;t be implemented. The following example uses an alternative approach that makes use of an event handler associated with the &#8220;Task&#8221; content type, that is used on workflow tasks lists. The event handler will run every time a task is updated and will get the task associated list item (the document) and start a custom workflow on the document when its Collect Feedback workflow instance gets completed. Let&#8217;s take a look at the code:</p>
<pre class="code"><span style="color: gray">/// &lt;summary&gt;
/// </span><span style="color: green">Event handler associated with the "Task" content types.
</span><span style="color: gray">/// &lt;/summary&gt;
</span><span style="color: blue">public class </span><span style="color: #2b91af">WorkflowCompletionCheckerEventReceiver </span>: SPItemEventReceiver
{
    <span style="color: green">//custom content type name
    </span><span style="color: blue">private const string </span>CUSTOM_CONTENT_TYPE_NAME = 
        <span style="color: #a31515">"My Custom Content Type"</span>;
    <span style="color: green">//task list workflow list id field
    </span><span style="color: blue">public const string </span>TASK_LIST_WORKFLOW_LIST_ID_FIELD_NAME = 
        <span style="color: #a31515">"ows_WorkflowListId"</span>;
    <span style="color: green">//task list workflow item id field
    </span><span style="color: blue">public const string </span>TASK_LIST_WORKFLOW_ITEM_ID_FIELD_NAME = 
        <span style="color: #a31515">"ows_WorkflowItemId"</span>;
    <span style="color: green">//collect feedback workflow id
    </span><span style="color: blue">public const string </span>COLLECT_FEEDBACK_WORKFLOW_ID = 
        <span style="color: #a31515">"46c389a4-6e18-476c-aa17-289b0c79fb8f"</span>;
    <span style="color: green">//custom workflow id
    </span><span style="color: blue">public const string </span>CUSTOM_WORKFLOW_ID = 
        <span style="color: #a31515">"96be29b0-1be4-4b99-a703-656e5470962b"</span>;

    <span style="color: gray">/// &lt;summary&gt;
    /// </span><span style="color: green">Event handler for item updated event.
    </span><span style="color: gray">/// &lt;/summary&gt;
    /// &lt;param name="properties"&gt;&lt;/param&gt;
    </span><span style="color: blue">public override void </span>ItemUpdated(SPItemEventProperties properties)
    {
        <span style="color: green">//start a custom workflow on a list item when a 
        //collect feedback workflow gets completed
        </span>StartCustomWorkflowOnTaskItemCompletion(properties);
    }

    <span style="color: gray">/// &lt;summary&gt;
    /// </span><span style="color: green">Checks if the "Collect Feedback" workflow 
    </span><span style="color: gray">/// </span><span style="color: green">instance on an item is completed. This method checkes a 
    </span><span style="color: gray">/// </span><span style="color: green">workflow task and verifies if they have been created by a 
    </span><span style="color: gray">/// </span><span style="color: green">"Collect Feedback" workflow and if the associated item is of 
    </span><span style="color: gray">/// </span><span style="color: green">my custom content type. If yes, it verifies if the workflow has 
    </span><span style="color: gray">/// </span><span style="color: green">been completed and if complete, starts a custom workflow 
    </span><span style="color: gray">/// </span><span style="color: green">on the associated item.
    </span><span style="color: gray">/// &lt;/summary&gt;
    /// &lt;param name="properties"&gt;&lt;/param&gt;
    </span><span style="color: blue">private void </span>StartCustomWorkflowOnTaskItemCompletion
        (SPItemEventProperties properties)
    {
        
        <span style="color: green">//get the task item
        </span>SPListItem listItem = properties.ListItem;
        <span style="color: blue">if </span>(listItem != <span style="color: blue">null</span>)
        {
            <span style="color: green">//get associated item id and associated list id

            //list id - ows_WorkflowListId field
            </span><span style="color: blue">object </span>associatedWorkflowListId = 
                listItem[TASK_LIST_WORKFLOW_LIST_ID_FIELD_NAME];
            <span style="color: green">//item id - ows_WorkflowItemId field
            </span><span style="color: blue">object </span>associatedWorkflowItemId = 
                listItem[TASK_LIST_WORKFLOW_ITEM_ID_FIELD_NAME];

            <span style="color: green">//get associated item
            </span><span style="color: blue">if </span>(associatedWorkflowItemId != <span style="color: blue">null 
                </span>&amp;&amp; associatedWorkflowListId != <span style="color: blue">null</span>)
            {
                <span style="color: green">//get task associated list item using 
                //its list id and item id
                </span>SPListItem associatedListItem = listItem.Web.Lists
                 .GetList(<span style="color: blue">new </span><span style="color: #2b91af">Guid</span>(associatedWorkflowListId.ToString()), <span style="color: blue">false</span>)
                 .GetItemById(<span style="color: blue">int</span>.Parse(associatedWorkflowItemId.ToString()));

                <span style="color: green">//check if item is of my custom content type
                </span><span style="color: blue">if </span>(associatedListItem.ContentType.Name
                    .Equals(CUSTOM_CONTENT_TYPE_NAME))
                {
                    <span style="color: green">//check if item has any workflow association
                    </span><span style="color: blue">if </span>(associatedListItem.Workflows.Count &gt; 0)
                    {
                        <span style="color: green">//iterate workflow associations and lookup 
                        //the collect feedback association
                        </span><span style="color: blue">foreach </span>(SPWorkflow workflow <span style="color: blue">in 
                            </span>associatedListItem.Workflows)
                        {
                            <span style="color: #2b91af">Guid </span>collectFeedbackWorkflowId = 
                                <span style="color: blue">new </span><span style="color: #2b91af">Guid</span>(COLLECT_FEEDBACK_WORKFLOW_ID);
                            <span style="color: green">//check if collect feedback workflow 
                            //instance is completed
                            </span><span style="color: blue">if </span>(workflow.ParentAssociation.BaseId 
                                == collectFeedbackWorkflowId
                                &amp;&amp; workflow.InternalState 
                                == SPWorkflowState.Completed)
                            {
                                <span style="color: green">//if collect feedback workflow instance is 
                                //completed, start custom workflow that is 
                                //associated with the item
                                </span>StartContentTypeWorkflow(associatedListItem, 
                                    CUSTOM_WORKFLOW_ID);
                            }
                        }
                    }
                }
            }
        }
    }

    <span style="color: gray">/// &lt;summary&gt;
    /// </span><span style="color: green">Starts a workflow associated to a content type programmatically.
    </span><span style="color: gray">/// &lt;/summary&gt;
    /// &lt;param name="properties"&gt;&lt;/param&gt;
    </span><span style="color: blue">public static void </span>StartContentTypeWorkflow(SPListItem listItem,
        <span style="color: blue">string </span>workflowId)
    {
        <span style="color: green">//start specified workflow that is associated with the item
        </span>SPWorkflowManager manager = listItem.Web.Site.WorkflowManager;
        <span style="color: green">//get list item content type
        </span>SPContentType contentType = listItem.ContentType;
        <span style="color: green">//get list item workflow associations
        </span>SPWorkflowAssociationCollection associationCollection = 
            contentType.WorkflowAssociations;
        <span style="color: green">//iterate all item workflow associations
        </span><span style="color: blue">foreach </span>(SPWorkflowAssociation association <span style="color: blue">in </span>associationCollection)
        {
            <span style="color: #2b91af">Guid </span>workflowGuid = <span style="color: blue">new </span><span style="color: #2b91af">Guid</span>(workflowId);
            <span style="color: green">//check if current workflow association matches 
            //the specified workflow
            </span><span style="color: blue">if </span>(association.BaseId == workflowGuid)
            {
                <span style="color: blue">string </span>data = association.AssociationData;

                <span style="color: green">//start workflow
                </span>SPWorkflow wf = manager.StartWorkflow(listItem, association, 
                    data, <span style="color: blue">false</span>);
            }
        }
    }
}</pre>
<p>In the previous example, the following actions are being performed:</p>
<ul>
<li>The ItemUpdated event in the event handler is being handled;</li>
<li>In the event handler, a reference to the task is obtained;</li>
<li>The associated list item is obtained using two columns of the task list item:
<ul>
<li>&#8220;ows_WorkflowListId&#8221; &#8211; holds the id of the list where the associated list item is created;</li>
<li>&#8220;ows_WorkflowItemId&#8221; &#8211; holds the id of the associated list item;</li>
</ul>
</li>
<li>The content type of the associated list item is checked for a match to my custom content type;</li>
<li>If there is a match, the list item workflow associations are checked for a match with the Collect Feedback workflow;</li>
<li>If there is a match and the workflow instance is completed, the custom workflow is started.</li>
</ul>
<h1>Related Articles</h1>
<p>To learn why your business should migrate to SharePoint Online and Office 365, click <a href="https://blogit.create.pt////miguelisidoro/2019/07/29/why-your-business-should-migrate-to-sharepoint-online-and-office-365-the-value-offer-part-1/" target="_blank" rel="noreferrer noopener">here</a> and <a href="https://blogit.create.pt////miguelisidoro/2019/07/29/why-your-business-should-migrate-to-sharepoint-online-and-office-365-the-value-offer-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you want to convert your tenant&#8217;s root classic site into a modern SharePoint site, click <a href="https://blogit.create.pt////miguelisidoro/2019/08/27/how-to-modernize-your-tenant-root-site-collection-in-office-365-using-invoke-spositeswap/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you are a SharePoint administrator or a SharePoint developer who<br />
wants to learn more about how to install a SharePoint farm in an automated way using PowerShell, I invite you to click <a href="https://blogit.create.pt////miguelisidoro/2018/07/28/how-to-install-a-sharepoint-2016-farm-using-powershell-and-autospinstaller-part-1/" target="_blank" rel="noopener noreferrer">here</a> and <a href="https://blogit.create.pt////miguelisidoro/2018/07/28/how-to-install-a-sharepoint-2016-farm-using-powershell-and-autospinstaller-part-2/" target="_blank" rel="noopener noreferrer">here</a>. The articles use AutoSPInstaller with a SharePoint 2016 farm but AutoSPInstaller support for SharePoint 2019 was already announced!</p>
<p>If you want to learn how to upgrade a SharePoint 2013 farm to SharePoint 2019, click <a href="https://blogit.create.pt////miguelisidoro/2019/03/06/how-to-upgrade-from-sharepoint-2013-to-sharepoint-2019-step-by-step-part-1/" target="_blank" rel="noreferrer noopener">here </a>and <a href="https://blogit.create.pt////miguelisidoro/2019/03/06/how-to-upgrade-from-sharepoint-2013-to-sharepoint-2019-step-by-step-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you want to learn all the steps and precautions necessary to successfully keep your SharePoint farm updated and be ready to start your move to the cloud, click <a href="https://blogit.create.pt////miguelisidoro/2019/04/08/how-to-install-sharepoint-cumulative-updates-in-a-sharepoint-farm-step-by-step/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you learn how to greatly speed up your SharePoint farm update process to ensure your SharePoint farm keeps updated and you stay one step closer to start your move to the cloud, click <a href="https://blogit.create.pt////miguelisidoro/2019/05/02/how-to-speed-up-the-installation-of-sharepoint-cumulative-updates-using-powershell-step-by-step/" target="_blank" rel="noreferrer noopener" aria-label="here (opens in a new tab)">here</a>.</p>
<p>If you want to learn how to upgrade a SharePoint 2010 farm to SharePoint 2016, click <a href="https://blogit.create.pt////miguelisidoro/2019/02/04/sharepoint-upgrade-upgrading-a-sharepoint-2010-farm-to-sharepoint-2016-step-by-step-part-1/" target="_blank" rel="noreferrer noopener">here </a>and <a href="https://blogit.create.pt////miguelisidoro/2019/02/04/sharepoint-upgrade-upgrading-a-sharepoint-2010-farm-to-sharepoint-2016-step-by-step-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you are new to SharePoint and Office 365 and want to learn all about it, take a look at these <a href="https://blogit.create.pt////miguelisidoro/2018/10/17/sharepoint-and-office-365-learning-resources/" target="_blank" rel="noopener noreferrer">learning resources</a>.</p>
<p>If you are work in a large organization who is using Office 365 or thinking to move to Office 365 and is considering between a single or multiple Office 365 tenants, I invite you to read <a href="https://blogit.create.pt////miguelisidoro/2019/01/07/pros-and-cons-of-single-tenant-vs-multiple-tenants-in-office-365/" target="_blank" rel="noreferrer noopener">this article</a>.</p>
<p>If you or your customers are not ready to move entirely to the Cloud and Office 365, a hybrid scenario could be an interesting scenario and SharePoint 2019 RTM was recently announced with improved hybrid support! To learn all about SharePoint 2019 and all its features, click <a href="https://blogit.create.pt////miguelisidoro/2018/11/01/meet-the-new-modern-sharepoint-server-sharepoint-2019-rtm-is-here/" target="_blank" rel="noopener noreferrer">here</a>.</p>
<p>If you want to know all about the latest SharePoint and Office 365 announcements from SharePoint Conference 2019, click <a href="https://blogit.create.pt////miguelisidoro/2019/06/05/whats-new-for-sharepoint-and-office-365-from-sharepoint-conference-2019-part-1/" target="_blank" rel="noreferrer noopener">here </a>and <a href="https://blogit.create.pt////miguelisidoro/2019/06/05/whats-new-for-sharepoint-and-office-365-from-sharepoint-conference-2019-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>Happy SharePointing!</p>
<p>The post <a href="https://blogit.create.pt/miguelisidoro/2008/10/25/sharepoint-2007-checking-if-a-workflow-instance-is-completed/">SharePoint 2007 &#8211; Checking if a Workflow Instance is Completed</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/miguelisidoro/2008/10/25/sharepoint-2007-checking-if-a-workflow-instance-is-completed/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PDC08 + TechEd Emea 2008</title>
		<link>https://blogit.create.pt/jota/2008/10/23/pdc08-teched-emea-2008/</link>
					<comments>https://blogit.create.pt/jota/2008/10/23/pdc08-teched-emea-2008/#respond</comments>
		
		<dc:creator><![CDATA[Jota]]></dc:creator>
		<pubDate>Thu, 23 Oct 2008 16:28:09 +0000</pubDate>
				<category><![CDATA[BizTalk Server]]></category>
		<category><![CDATA[BizTalk Services]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Model Driven Development]]></category>
		<category><![CDATA[Create It]]></category>
		<category><![CDATA[Workflows]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[Arquitectura]]></category>
		<category><![CDATA[MsdnArquitecturaPT]]></category>
		<category><![CDATA[Posts in English]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/joaomartins/?p=961</guid>

					<description><![CDATA[<p>Next week I’ll be off at PDC08, which is shaping up to be as good as PDC05 was, with a lot of sessions on Today’s hot topic: Cloud Computing. One week later, I’ll be at the Ask-The-Experts booths at TechEd EMEA 2008 Developers in Barcelona (my colleague and SharePoint God&#160;Raúl is also attending the conference), [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/jota/2008/10/23/pdc08-teched-emea-2008/">PDC08 + TechEd Emea 2008</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Next week I’ll be off at <a href="http://www.microsoftpdc.com/">PDC08</a>, which is shaping up to be as good as PDC05 was, with a lot of sessions on Today’s hot topic: <strong>Cloud Computing</strong>. One week later, I’ll be at the Ask-The-Experts booths at <a href="http://www.microsoft.com/emea/teched2008/developer/default.aspx">TechEd EMEA 2008 Developers</a> in Barcelona (my colleague and <strong>SharePoint God</strong>&#160;<a href="http://blogit.create.pt/blogs/raulribeiro">Raúl</a> is also attending the conference), focused on making contacts and maybe attending some of the sessions missed from PDC that will be repeated there. <a href="http://blog.deepdivein.net/">Pedro Rosa</a> from Microsoft Portugal is the owner of the dev track, and has some pretty good sessions lined up.</p>
<p>If you happen to be at any of the events and want to meet, contact me using the form on the blog.</p>
<p>You just <em>gotta </em>love technology… 🙂 See you there.</p>
<p>The post <a href="https://blogit.create.pt/jota/2008/10/23/pdc08-teched-emea-2008/">PDC08 + TechEd Emea 2008</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/jota/2008/10/23/pdc08-teched-emea-2008/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>&#8220;The E-Myth Revisited&#8221; and The World After Summer</title>
		<link>https://blogit.create.pt/jota/2008/08/26/the-e-myth-revisited-and-the-world-after-summer/</link>
					<comments>https://blogit.create.pt/jota/2008/08/26/the-e-myth-revisited-and-the-world-after-summer/#respond</comments>
		
		<dc:creator><![CDATA[Jota]]></dc:creator>
		<pubDate>Tue, 26 Aug 2008 16:57:00 +0000</pubDate>
				<category><![CDATA[BizTalk Server]]></category>
		<category><![CDATA[BizTalk Services]]></category>
		<category><![CDATA[Off Topic]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Create It]]></category>
		<category><![CDATA[Workflows]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[Posts in English]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/joaomartins/?p=1061</guid>

					<description><![CDATA[<p>I&#039;ve been reading &#34;The E Myth Revisited&#34;, by Michael Gerber. The book is all about entrepreneurs and small companies, and why they usually fail. The following quote is right at its start: &#34;Businesses start and fail in the United States at an increasingly staggering rate. Every year, over a million people in this country start [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/jota/2008/08/26/the-e-myth-revisited-and-the-world-after-summer/">&#8220;The E-Myth Revisited&#8221; and The World After Summer</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I&#039;ve been reading &quot;<em>The E Myth Revisited</em>&quot;, by Michael Gerber. The book is all about entrepreneurs and small companies, and why they usually fail. The following quote is right at its start:</p>
<blockquote>
<p><em>&quot;Businesses start and fail in the United States at an increasingly staggering rate. Every year, over a million people in this country start a business of some sort. Statistics tell us that <strong>by the end of the first year at least 40 percent of them will be out of business</strong>. <strong>Within five years, more than 80 percent of them will have failed</strong>.&nbsp; [&#8230;] And <strong>more than 80 percent of the small businesses that survive the the first five years fail in the second five</strong>.&quot;</em></p>
</blockquote>
<p><a href="http://www.create.pt">Create It</a> is now over 7 years old, and 16 people strong.&nbsp; It makes me proud to be in the small percentage of companies that do make it (although we are still 3 years away from the danger zone). 🙂</p>
<p>Meanwhile, on the technical side, I&#039;ve been trying out the new <strong>BizTalk Services R12</strong> release, which includes (hosted) <a href="http://biztalk.net/Workflow.aspx">Workflow support</a>. It&#039;s limited in the sense that there are not many activities included, and there&#039;s not yet rich and integrated tooling, but it&#039;s an interesting start nonetheless. Well worth exploring. And on another track, I&#039;ve been looking into <a href="https://connect.microsoft.com/Downloads/Downloads.aspx?SiteID=65">BizTalk Server R3</a>. The new features do look interesting, although clearly in the &quot;evolution&quot; side of things.</p>
<p>Finally, I&#039;ve been getting ready for the <a href="http://www.microsoftpdc.com">PDC2008</a>, in October, where it&#039;s interesting to note that the topic &quot;Cloud Services&quot; is the one with most <a href="https://sessions.microsoftpdc.com/public/sessions.aspx">sessions</a>. If you want to learn more about this topic, I recommend you subscribe to the <a href="http://groups.google.com/group/cloud-computing">Cloud Computing group</a> hosted at Google Groups (but not specifically Google-related or sponsored). Interesting discussions there.</p>
<p>The post <a href="https://blogit.create.pt/jota/2008/08/26/the-e-myth-revisited-and-the-world-after-summer/">&#8220;The E-Myth Revisited&#8221; and The World After Summer</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/jota/2008/08/26/the-e-myth-revisited-and-the-world-after-summer/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SharePoint 2007 &#8211; New instances of this workflow template are currently disallowed</title>
		<link>https://blogit.create.pt/miguelisidoro/2008/07/12/sharepoint-2007-new-instances-of-this-workflow-template-are-currently-disallowed/</link>
					<comments>https://blogit.create.pt/miguelisidoro/2008/07/12/sharepoint-2007-new-instances-of-this-workflow-template-are-currently-disallowed/#respond</comments>
		
		<dc:creator><![CDATA[Miguel Isidoro]]></dc:creator>
		<pubDate>Sat, 12 Jul 2008 11:28:45 +0000</pubDate>
				<category><![CDATA[Windows Workflow Foundation]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Workflows]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[WSS]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/miguelisidoro/?p=151</guid>

					<description><![CDATA[<p>When creating a new custom workflow project using Visual Studio 2008, a strong key file (.snk) file is automatically included in the project to sign the workflow assembly. A few days ago, I started developing a SharePoint 2007 Sequential Workflow project. After finishing developing the workflow, I deployed it and started testing it by associating [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/miguelisidoro/2008/07/12/sharepoint-2007-new-instances-of-this-workflow-template-are-currently-disallowed/">SharePoint 2007 &#8211; New instances of this workflow template are currently disallowed</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When creating a new custom workflow project using Visual Studio 2008, a strong key file (.snk) file is automatically included in the project to sign the workflow assembly. A few days ago, I started developing a SharePoint 2007 Sequential Workflow project. After finishing developing the workflow, I deployed it and started testing it by associating the workflow to a content type (Site Settings &gt; Site Content Type Gallery &gt; Site Content Type &gt; Workflow settings). I then noticed that the strong key file that was being used to sign the workflow assembly wasn&#8217;t the one I usually use and modified the project settings so that it started using it. After recompiling the project and redeploying the workflow, I started to get an error message: &#8220;New instances of this workflow template are currently disallowed&#8221;. The reason for this message to appear is that a new version version of the workflow had been deployed (same assembly with a different public key token due to the change in the strong key file used to sign the assembly). In these situations, the existing workflow associations made from older versions of the workflow are automatically set to &#8220;No New Instances&#8221;, meaning that new instances of the workflow for those workflow associations are not allowed. The image below shows the Remove Workflow page with my custom workflow association set to &#8220;No New Instances&#8221;. To access this page, go to Site Settings &gt; Site Content Type Gallery &gt; Site Content Type &gt; Workflow settings &gt; Remove Workflows if the workflow is associated with a content type.</p>
<p><img decoding="async" src="http://pic90.picturetrail.com/VOL2147/10903553/19399056/325207336.jpg" /></p>
<p>To solve the problem, all you have to do is to set the workflow association to &#8220;Allow&#8221; and new instances of the workflow can again be created.</p>
<h1>Related Articles</h1>
<p>To learn why your business should migrate to SharePoint Online and Office 365, click <a href="https://blogit.create.pt////miguelisidoro/2019/07/29/why-your-business-should-migrate-to-sharepoint-online-and-office-365-the-value-offer-part-1/" target="_blank" rel="noreferrer noopener">here</a> and <a href="https://blogit.create.pt////miguelisidoro/2019/07/29/why-your-business-should-migrate-to-sharepoint-online-and-office-365-the-value-offer-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you want to convert your tenant&#8217;s root classic site into a modern SharePoint site, click <a href="https://blogit.create.pt////miguelisidoro/2019/08/27/how-to-modernize-your-tenant-root-site-collection-in-office-365-using-invoke-spositeswap/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you are a SharePoint administrator or a SharePoint developer who wants to learn more about how to install a SharePoint farm in an automated way using PowerShell, I invite you to click <a href="https://blogit.create.pt////miguelisidoro/2018/07/28/how-to-install-a-sharepoint-2016-farm-using-powershell-and-autospinstaller-part-1/" target="_blank" rel="noopener noreferrer">here</a> and <a href="https://blogit.create.pt////miguelisidoro/2018/07/28/how-to-install-a-sharepoint-2016-farm-using-powershell-and-autospinstaller-part-2/" target="_blank" rel="noopener noreferrer">here</a>. The articles use AutoSPInstaller with a SharePoint 2016 farm but AutoSPInstaller support for SharePoint 2019 was already announced!</p>
<p>If you want to learn how to upgrade a SharePoint 2013 farm to SharePoint 2019, click <a href="https://blogit.create.pt////miguelisidoro/2019/03/06/how-to-upgrade-from-sharepoint-2013-to-sharepoint-2019-step-by-step-part-1/" target="_blank" rel="noreferrer noopener">here </a>and <a href="https://blogit.create.pt////miguelisidoro/2019/03/06/how-to-upgrade-from-sharepoint-2013-to-sharepoint-2019-step-by-step-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you want to learn all the steps and precautions necessary to successfully keep your SharePoint farm updated and be ready to start your move to the cloud, click <a href="https://blogit.create.pt////miguelisidoro/2019/04/08/how-to-install-sharepoint-cumulative-updates-in-a-sharepoint-farm-step-by-step/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you learn how to greatly speed up your SharePoint farm update process to ensure your SharePoint farm keeps updated and you stay one step closer to start your move to the cloud, click <a href="https://blogit.create.pt////miguelisidoro/2019/05/02/how-to-speed-up-the-installation-of-sharepoint-cumulative-updates-using-powershell-step-by-step/" target="_blank" rel="noreferrer noopener" aria-label="here (opens in a new tab)">here</a>.</p>
<p>If you want to learn how to upgrade a SharePoint 2010 farm to SharePoint 2016, click <a href="https://blogit.create.pt////miguelisidoro/2019/02/04/sharepoint-upgrade-upgrading-a-sharepoint-2010-farm-to-sharepoint-2016-step-by-step-part-1/" target="_blank" rel="noreferrer noopener">here </a>and <a href="https://blogit.create.pt////miguelisidoro/2019/02/04/sharepoint-upgrade-upgrading-a-sharepoint-2010-farm-to-sharepoint-2016-step-by-step-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you are new to SharePoint and Office 365 and want to learn all about it, take a look at these <a href="https://blogit.create.pt////miguelisidoro/2018/10/17/sharepoint-and-office-365-learning-resources/" target="_blank" rel="noopener noreferrer">learning resources</a>.</p>
<p>If you are work in a large organization who is using Office 365 or thinking to move to Office 365 and is considering between a single or multiple Office 365 tenants, I invite you to read <a href="https://blogit.create.pt////miguelisidoro/2019/01/07/pros-and-cons-of-single-tenant-vs-multiple-tenants-in-office-365/" target="_blank" rel="noreferrer noopener">this article</a>.</p>
<p>If you or your customers are not ready to move entirely to the Cloud and Office 365, a hybrid scenario could be an interesting scenario and SharePoint 2019 RTM was recently announced with improved hybrid support! To learn all about SharePoint 2019 and all its features, click <a href="https://blogit.create.pt////miguelisidoro/2018/11/01/meet-the-new-modern-sharepoint-server-sharepoint-2019-rtm-is-here/" target="_blank" rel="noopener noreferrer">here</a>.</p>
<p>If you want to know all about the latest SharePoint and Office 365 announcements from SharePoint Conference 2019, click <a href="https://blogit.create.pt////miguelisidoro/2019/06/05/whats-new-for-sharepoint-and-office-365-from-sharepoint-conference-2019-part-1/" target="_blank" rel="noreferrer noopener">here </a>and <a href="https://blogit.create.pt////miguelisidoro/2019/06/05/whats-new-for-sharepoint-and-office-365-from-sharepoint-conference-2019-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>Happy SharePointing!</p>
<p>The post <a href="https://blogit.create.pt/miguelisidoro/2008/07/12/sharepoint-2007-new-instances-of-this-workflow-template-are-currently-disallowed/">SharePoint 2007 &#8211; New instances of this workflow template are currently disallowed</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/miguelisidoro/2008/07/12/sharepoint-2007-new-instances-of-this-workflow-template-are-currently-disallowed/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SharePoint 2007 &#8211; Start a Workflow Programmatically</title>
		<link>https://blogit.create.pt/miguelisidoro/2008/07/05/sharepoint-2007-start-a-workflow-programmatically/</link>
					<comments>https://blogit.create.pt/miguelisidoro/2008/07/05/sharepoint-2007-start-a-workflow-programmatically/#respond</comments>
		
		<dc:creator><![CDATA[Miguel Isidoro]]></dc:creator>
		<pubDate>Sat, 05 Jul 2008 09:27:23 +0000</pubDate>
				<category><![CDATA[Windows Workflow Foundation]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Workflows]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[WSS]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/miguelisidoro/?p=171</guid>

					<description><![CDATA[<p>Introduction This blog post will show you how to start a workflow programmatically every time an item is updated in a SharePoint list. For those who don’t know, Windows Workflow Foundation (WF) is the new engine for building custom workflows (you can find more information about WF on the official web site). It was released [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/miguelisidoro/2008/07/05/sharepoint-2007-start-a-workflow-programmatically/">SharePoint 2007 &#8211; Start a Workflow Programmatically</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1>Introduction</h1>
<p>This blog post will show you how to start a workflow programmatically every time an item is updated in a SharePoint list. For those who don’t know, Windows Workflow Foundation (WF) is the new engine for building custom workflows (you can find more information about WF on the <a href="http://msdn.microsoft.com/winfx/technologies/workflow/default.aspx">official web site</a>). It was released as part of the .NET Framework 3.0 along with <a href="http://msdn2.microsoft.com/en-us/netframework/aa663326.aspx">Windows Presentation Foundation (WPF)</a> and <a href="http://msdn2.microsoft.com/en-us/netframework/aa663324.aspx">Windows Communication Foundation (WCF)</a>. In the SharePoint world, workflows can be associated both to a list and to a content type. Both options are valid and the choice for one or the other option depends on your needs:</p>
<ul>
<li>If you want to run a workflow in a list, independently of the content type of each list item, you should associate the workflow to a list. If you have more than one content type associated to the list, care should be taken in the workflow implementation since each content type can have different columns that may not be present in the other content types;</li>
<li>If you want to run the workflow on all items of a specific content type, you should associate the workflow to a content type. The workflow will be associated to all list items from that content type in all lists across a site or the whole site collection (depending on the scope of the workflow, typically defined in its deployment feature) that are associated with the content type.</li>
</ul>
<h1>Example</h1>
<p>The following example shows how both options can be addressed. This example uses an event handler and starts a workflow every time an item is updated in a SharePoint list.</p>
<pre class="code"></pre>
<pre class="code"><span style="color: blue">public class </span><span style="color: #2b91af">ProgrammaticWorkflowInitiationEventReceiver </span>: SPItemEventReceiver
{
    <span style="color: gray">/// &lt;summary&gt;
    /// </span><span style="color: green">Event handler for item updated event.
    </span><span style="color: gray">/// &lt;/summary&gt;
    /// &lt;param name="properties"&gt;&lt;/param&gt;
    </span><span style="color: blue">public override void </span>ItemUpdated(SPItemEventProperties properties)
    {
        <span style="color: green">//use this method if the workflow is associated to a list
        </span>StartListWorkflow(properties);

        <span style="color: green">//use this method if the workflow is associated to a content type
        </span>StartContentTypeWorkflow(properties);
    }

    <span style="color: gray">/// &lt;summary&gt;
    /// </span><span style="color: green">Starts a workflow associated to a list programmatically.
    </span><span style="color: gray">/// &lt;/summary&gt;
    /// &lt;param name="properties"&gt;&lt;/param&gt;
    </span><span style="color: blue">private void </span>StartListWorkflow(SPItemEventProperties properties)
    {
        <span style="color: green">//get list item from event handler properties
        </span>SPListItem listItem = properties.ListItem;

        <span style="color: blue">using </span>(SPWeb web = listItem.Web)
        {
            <span style="color: blue">using </span>(SPSite site = web.Site)
            {
                <span style="color: green">//obtain an instance of SPWorkflowManager 
                //which will be later used to start the workflow
                </span>SPWorkflowManager manager = site.WorkflowManager;
                <span style="color: green">//get item's parent list
                </span>SPList parentList = listItem.ParentList;
                <span style="color: green">//get all workflows that are associated with the list
                </span>SPWorkflowAssociationCollection associationCollection = 
                    parentList.WorkflowAssociations;
                <span style="color: green">//lookup and start the worflow
                </span>LookupAndStartWorkflow(listItem, manager,
                    associationCollection, <span style="color: #a31515">"FDEDCC37-4D8A-44ba-8E22-57B2669A887C"</span>);
            }
        }
    }

    <span style="color: gray">/// &lt;summary&gt;
    /// </span><span style="color: green">Starts a workflow associated to a content type programmatically.
    </span><span style="color: gray">/// &lt;/summary&gt;
    /// &lt;param name="properties"&gt;&lt;/param&gt;
    </span><span style="color: blue">private void </span>StartContentTypeWorkflow(SPItemEventProperties properties)
    {
        <span style="color: green">//get list item from event handler properties
        </span>SPListItem listItem = properties.ListItem;

        <span style="color: blue">using </span>(SPWeb web = listItem.Web)
        {
            <span style="color: blue">using </span>(SPSite site = web.Site)
            {
                <span style="color: green">//obtain an instance of SPWorkflowManager 
                //which will be later used to start the workflow
                </span>SPWorkflowManager manager = site.WorkflowManager;
                <span style="color: green">//get item's content type
                </span>SPContentType contentType = listItem.ContentType;
                <span style="color: green">//get all workflows that are associated with the content type
                </span>SPWorkflowAssociationCollection associationCollection = 
                    contentType.WorkflowAssociations;
                <span style="color: green">//lookup and start the worflow
                </span>LookupAndStartWorkflow(listItem, manager,
                    associationCollection, <span style="color: #a31515">"FDEDCC37-4D8A-44ba-8E22-57B2669A887C"</span>);
            }
        }
    }

    <span style="color: gray">/// &lt;summary&gt;
    /// </span><span style="color: green">Lookup and start the workflow.
    </span><span style="color: gray">/// &lt;/summary&gt;
    /// &lt;param name="listItem"&gt;&lt;/param&gt;
    /// &lt;param name="manager"&gt;&lt;/param&gt;
    /// &lt;param name="associationCollection"&gt;&lt;/param&gt;
    /// &lt;param name="workflowId"&gt;&lt;/param&gt;
    </span><span style="color: blue">private static void </span>LookupAndStartWorkflow(SPListItem listItem, 
        SPWorkflowManager manager, 
        SPWorkflowAssociationCollection associationCollection, 
        <span style="color: blue">string </span>workflowId)
    {
        <span style="color: green">//iterate workflow associations and lookup the workflow to be started
        </span><span style="color: blue">foreach </span>(SPWorkflowAssociation association <span style="color: blue">in </span>associationCollection)
        {
            <span style="color: green">//if the workflow association matches the workflow we are looking for,
            //get its association data and start the workflow
            </span><span style="color: #2b91af">Guid </span>workflowGuid = <span style="color: blue">new </span><span style="color: #2b91af">Guid</span>(workflowId);
            <span style="color: blue">if </span>(association.BaseId == workflowGuid)
            {
                <span style="color: green">//get workflow association data
                </span><span style="color: blue">string </span>data = association.AssociationData;

                <span style="color: green">//start workflow
                </span>SPWorkflow wf = manager.StartWorkflow(listItem, association, data);
            }
        }
    }
}</pre>
<p>In the previous example, the following actions are being performed:</p>
<ul>
<li>The ItemUpdated event in the event handler is being handled. For demonstration purposes, I am assuming that two workflow associations were created, one to a list and another to a content type;</li>
<li>A call is made to the <em>StartListWorkflow</em> method, which starts the workflow associated with a list;</li>
<li>A call is made to the <em>StartContentTypeWorkflow</em> method, which starts the workflow associated with a content type.</li>
</ul>
<h1>Related Articles</h1>
<p>To learn why your business should migrate to SharePoint Online and Office 365, click <a href="https://blogit.create.pt////miguelisidoro/2019/07/29/why-your-business-should-migrate-to-sharepoint-online-and-office-365-the-value-offer-part-1/" target="_blank" rel="noreferrer noopener">here</a> and <a href="https://blogit.create.pt////miguelisidoro/2019/07/29/why-your-business-should-migrate-to-sharepoint-online-and-office-365-the-value-offer-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you want to convert your tenant&#8217;s root classic site into a modern SharePoint site, click <a href="https://blogit.create.pt////miguelisidoro/2019/08/27/how-to-modernize-your-tenant-root-site-collection-in-office-365-using-invoke-spositeswap/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you are a SharePoint administrator or a SharePoint developer who wants to learn more about how to install a SharePoint farm in an automated way using PowerShell, I invite you to click <a href="https://blogit.create.pt////miguelisidoro/2018/07/28/how-to-install-a-sharepoint-2016-farm-using-powershell-and-autospinstaller-part-1/" target="_blank" rel="noopener noreferrer">here</a> and <a href="https://blogit.create.pt////miguelisidoro/2018/07/28/how-to-install-a-sharepoint-2016-farm-using-powershell-and-autospinstaller-part-2/" target="_blank" rel="noopener noreferrer">here</a>. The articles use AutoSPInstaller with a SharePoint 2016 farm but AutoSPInstaller support for SharePoint 2019 was already announced!</p>
<p>If you want to learn how to upgrade a SharePoint 2013 farm to SharePoint 2019, click <a href="https://blogit.create.pt////miguelisidoro/2019/03/06/how-to-upgrade-from-sharepoint-2013-to-sharepoint-2019-step-by-step-part-1/" target="_blank" rel="noreferrer noopener">here </a>and <a href="https://blogit.create.pt////miguelisidoro/2019/03/06/how-to-upgrade-from-sharepoint-2013-to-sharepoint-2019-step-by-step-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you want to learn all the steps and precautions necessary to successfully keep your SharePoint farm updated and be ready to start your move to the cloud, click <a href="https://blogit.create.pt////miguelisidoro/2019/04/08/how-to-install-sharepoint-cumulative-updates-in-a-sharepoint-farm-step-by-step/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you learn how to greatly speed up your SharePoint farm update process to ensure your SharePoint farm keeps updated and you stay one step closer to start your move to the cloud, click <a href="https://blogit.create.pt////miguelisidoro/2019/05/02/how-to-speed-up-the-installation-of-sharepoint-cumulative-updates-using-powershell-step-by-step/" target="_blank" rel="noreferrer noopener" aria-label="here (opens in a new tab)">here</a>.</p>
<p>If you want to learn how to upgrade a SharePoint 2010 farm to SharePoint 2016, click <a href="https://blogit.create.pt////miguelisidoro/2019/02/04/sharepoint-upgrade-upgrading-a-sharepoint-2010-farm-to-sharepoint-2016-step-by-step-part-1/" target="_blank" rel="noreferrer noopener">here </a>and <a href="https://blogit.create.pt////miguelisidoro/2019/02/04/sharepoint-upgrade-upgrading-a-sharepoint-2010-farm-to-sharepoint-2016-step-by-step-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you are new to SharePoint and Office 365 and want to learn all about it, take a look at these <a href="https://blogit.create.pt////miguelisidoro/2018/10/17/sharepoint-and-office-365-learning-resources/" target="_blank" rel="noopener noreferrer">learning resources</a>.</p>
<p>If you are work in a large organization who is using Office 365 or thinking to move to Office 365 and is considering between a single or multiple Office 365 tenants, I invite you to read <a href="https://blogit.create.pt////miguelisidoro/2019/01/07/pros-and-cons-of-single-tenant-vs-multiple-tenants-in-office-365/" target="_blank" rel="noreferrer noopener">this article</a>.</p>
<p>If you or your customers are not ready to move entirely to the Cloud and Office 365, a hybrid scenario could be an interesting scenario and SharePoint 2019 RTM was recently announced with improved hybrid support! To learn all about SharePoint 2019 and all its features, click <a href="https://blogit.create.pt////miguelisidoro/2018/11/01/meet-the-new-modern-sharepoint-server-sharepoint-2019-rtm-is-here/" target="_blank" rel="noopener noreferrer">here</a>.</p>
<p>If you want to know all about the latest SharePoint and Office 365 announcements from SharePoint Conference 2019, click <a href="https://blogit.create.pt////miguelisidoro/2019/06/05/whats-new-for-sharepoint-and-office-365-from-sharepoint-conference-2019-part-1/" target="_blank" rel="noreferrer noopener">here </a>and <a href="https://blogit.create.pt////miguelisidoro/2019/06/05/whats-new-for-sharepoint-and-office-365-from-sharepoint-conference-2019-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>Happy SharePointing!</p>
<p>The post <a href="https://blogit.create.pt/miguelisidoro/2008/07/05/sharepoint-2007-start-a-workflow-programmatically/">SharePoint 2007 &#8211; Start a Workflow Programmatically</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/miguelisidoro/2008/07/05/sharepoint-2007-start-a-workflow-programmatically/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to &#8211; Validate Windows Workflow custom activity input</title>
		<link>https://blogit.create.pt/tiagooliveira/2008/06/11/how-to-validate-windows-workflow-custom-activity-input/</link>
					<comments>https://blogit.create.pt/tiagooliveira/2008/06/11/how-to-validate-windows-workflow-custom-activity-input/#respond</comments>
		
		<dc:creator><![CDATA[Tiago Oliveira]]></dc:creator>
		<pubDate>Wed, 11 Jun 2008 09:57:00 +0000</pubDate>
				<category><![CDATA[Windows Workflow Foundation]]></category>
		<category><![CDATA[Workflows]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/tiagooliveira/?p=101</guid>

					<description><![CDATA[<p>Windows Workflow allow us to perform custom validator input that is executed&#160;at design and compile time. The error output is similar as Biztalk Orchestration shape errors. Adding a validator&#160;to a&#160;custom activity involves&#160;two steps: Create a class that derives from ActivityValidator class and override Validate method; Add a ActivityValidator attribute with the validator type to the [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/tiagooliveira/2008/06/11/how-to-validate-windows-workflow-custom-activity-input/">How to &#8211; Validate Windows Workflow custom activity input</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Windows Workflow allow us to perform custom validator input that is executed&nbsp;at design and compile time. The error output is similar as Biztalk Orchestration shape errors. </p>
<p>Adding a validator&nbsp;to a&nbsp;custom activity involves&nbsp;two steps:</p>
<ol start="1">
<li>Create a class that derives from <a href="http://msdn.microsoft.com/pt-br/library/system.workflow.componentmodel.compiler.activityvalidator.aspx" title="ActivityValidator" target="_blank">ActivityValidator</a> class and override <a href="http://msdn.microsoft.com/pt-br/library/system.workflow.componentmodel.compiler.activityvalidator.validate.aspx" target="_blank">Validate </a>method;</li>
<li>Add a <a href="http://msdn.microsoft.com/pt-br/library/ms590699.aspx" title="ActivityValidator attribute" target="_blank">ActivityValidator attribute</a> with the validator type to the custom activity;</li>
</ol>
<p>As an example,&nbsp;i&#039;m going to show a validator creation that verifies if a specific property is set.</p>
<p>I have already created a custom activity that is called Hello and have a property that receives the user name. To validate if the activity proprety is set, i&#039;m going to create a validator.&nbsp;</p>
<p><strong>ActivityValidator class creation:</strong></p>
<p>As said early, to create a validator i have to create a class that derives from ActivityValidator. To perform the validation i have to override the validate method and set the validation code.
 </p>
<p style="margin: 0px"><span style="color: blue">using</span> System;</p>
<p style="margin: 0px"><span style="color: blue">using</span><br />
System.Text.RegularExpressions;</p>
<p style="margin: 0px"><span style="color: blue">using</span><br />
System.Workflow.ComponentModel.Compiler;</p>
<p><font color="#0000ff" size="2"></p>
<p>internal sealed class<font size="2"> </font><font color="#2b91af" size="2">ExampleValidator</font><font size="2"> : </font><font color="#2b91af" size="2">ActivityValidator</font> {</p>
<p></font><font size="2"></p>
<p><font color="#0000ff" size="2">&nbsp;&nbsp;&nbsp; public</font><font size="2"> </font><font color="#0000ff" size="2">override</font><font size="2"> </font><font color="#2b91af" size="2">ValidationErrorCollection</font><font size="2"> Validate (</font><font color="#2b91af" size="2">ValidationManager</font><font size="2"> manager, </font><font color="#0000ff" size="2">object</font><font size="2"> obj) <br />&nbsp;&nbsp;&nbsp; {</p>
<p><font color="#0000ff" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if</font><font size="2"> (manager == </font><font color="#0000ff" size="2">null</font><font color="#0000ff" size="2"> throw</font><font size="2"> </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#2b91af" size="2">ArgumentNullException</font><font size="2">(</font><font color="#800080" size="2">&quot;Invalid manager.&quot;</font>);<font size="2">)</p>
<p><font size="2"></p>
<p><font color="#0000ff" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if</font><font size="2"> (obj == </font><font color="#0000ff" size="2">null</font><font color="#0000ff" size="2"> throw</font><font size="2"> </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#2b91af" size="2">ArgumentNullException</font><font size="2">(</font><font color="#800080" size="2">&quot;Invalid activity.&quot;</font>);<font size="2">)</p>
<p><font size="2"></p>
<p><font color="#2b91af" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelloActivity </font><font size="2">activity = obj </font><font color="#0000ff" size="2">as</font><font size="2"> </font><font><font><font><font><font><font><font size="2"><font size="2"><font size="2"><font size="2"><font size="2"><font size="2"><font color="#2b91af" size="2">HelloActivity </font></font></font></font></font></font></font></font></font></font></font></font></font><font size="2"></p>
<p><font color="#0000ff" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if</font><font size="2"> (activity == </font><font color="#0000ff" size="2">null</font><font color="#0000ff" size="2">) throw</font><font size="2"> </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#2b91af" size="2">InvalidOperationException</font><font size="2">(</font><font color="#800080" size="2">&quot;Activity should be a HelloActivity.</font><font color="#800080" size="2">&quot;</font>);<font size="2"></p>
<p><font size="2"></p>
<p><font color="#0000ff" size="2"></font><font size="2"></p>
<p><font size="2"></p>
<p><font color="#2b91af" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ValidationErrorCollection</font><font size="2"> errors = </font><font color="#0000ff" size="2">base</font><font size="2">.Validate(manager, obj);</font></p>
<p></font></p>
<p></font></p>
<p></font></p>
<p></font></p>
<p></font></p>
<p></font></p>
<p></font></p>
<p></font></p>
<p></font></p>
<p></font></p>
<p></font><font size="2"></p>
<p><font color="#008000" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Validate UserName property setting validationErrorCollection with information<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // about the property that causes the error.<br />
</font></p>
<p></font><font color="#008000" size="2"></font><font size="2"></p>
<p><font color="#0000ff" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if</font><font size="2"> (</font><font color="#0000ff" size="2">string</font><font size="2">.IsNullOrEmpty(activity.UserName)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font><font><font size="2"><font size="2">errors.Add(<font color="#2b91af" size="2">ValidationError</font><font size="2">.GetNotSetValidationError(</font><font color="#800080" size="2">&quot;Username&quot;</font><font size="2">));</font></font></font></font></font><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;<font size="2"><br />
</font></p>
<p></font><font size="2"></p>
<p><font size="2"></p>
<p><font size="2"></p>
<p><font color="#0000ff" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return</font><font size="2"> errors;<br />&nbsp;&nbsp;&nbsp; }<br />}</p>
<p>&nbsp;</p>
<p><font size="2"><font size="2"><font size="2"><font size="2"><font><font><font><font><font size="2"><font size="2"><font size="2"><font size="2"><strong>Custom activity </strong></font></font></font></font></font></font></font></font></font></font></font></font><font><font><font><font><font size="2"><font size="2"><font size="2"><font size="2"><strong>and validator association<br /></strong></font></font></font></font></font></font></font></font></p>
<p></font></p>
<p></font></p>
<p></font></p>
<p></font><font size="2"></p>
<p><font size="2"></p>
<p><font size="2"></p>
<p><font size="2"></p>
<p><font><font><font><font><font size="2"><font size="2"><font size="2"><font size="2"> </font></font></font></font></font></font></font></font></p>
<p>To associate the validator with the custom activity it&#039;s used the activityvalidator attribute.</p>
<p>[<font><font><font><font><font size="2"><font size="2"><font size="2"><font size="2"><font><font color="#0000ff" size="2"><font color="#2b91af" size="2">ActivityValidator</font></font></font></font></font></font></font></font></font></font></font>(<font size="2"><font size="2"><font size="2"><font size="2"><font><font color="#0000ff" size="2">typeof</font></font></font></font></font></font>(<font><font color="#0000ff" size="2"><font color="#2b91af" size="2">ExampleValidator</font></font></font>))]</p>
<p><font><font color="#0000ff" size="2">public sealed class<font size="2"> </font><font color="#2b91af" size="2">HelloActivity</font><font size="2"> : </font><font color="#2b91af" size="2">System.Workflow.ComponentModel.Activity</font> {..</font></font></p>
<p>&nbsp;</p>
<p>In the end the custom activity validator error will be show like this:</p>
<p><img decoding="async" alt="WFValidator" src="http://pic50.picturetrail.com/VOL460/10402378/18629414/344944713.jpg" title="WFValidator">&nbsp;</p>
<p></font></p>
<p></font></p>
<p></font></p>
<p></font></p>
<p>The post <a href="https://blogit.create.pt/tiagooliveira/2008/06/11/how-to-validate-windows-workflow-custom-activity-input/">How to &#8211; Validate Windows Workflow custom activity input</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/tiagooliveira/2008/06/11/how-to-validate-windows-workflow-custom-activity-input/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Windows Workflow &#8211; Using the ListenActivity</title>
		<link>https://blogit.create.pt/tiagolucas/2008/04/17/windows-workflow-using-the-listenactivity/</link>
					<comments>https://blogit.create.pt/tiagolucas/2008/04/17/windows-workflow-using-the-listenactivity/#respond</comments>
		
		<dc:creator><![CDATA[Tiago Lucas]]></dc:creator>
		<pubDate>Thu, 17 Apr 2008 13:12:31 +0000</pubDate>
				<category><![CDATA[Windows Workflow Foundation]]></category>
		<category><![CDATA[Workflows]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/tiagolucas/?p=41</guid>

					<description><![CDATA[<p>When the workflow requires interaction with the outside world this activity can become very helpful. The ListenActivity as its name suggests listens for incoming wake-up calls on the workflow. This activity idles the workflow, and waits for something to happen on one of its branches. When this activity is dropped into the workflow designer two [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/tiagolucas/2008/04/17/windows-workflow-using-the-listenactivity/">Windows Workflow &#8211; Using the ListenActivity</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When the workflow requires interaction with the outside world this activity can become very helpful. </p>
<p>The <a href="http://msdn2.microsoft.com/en-us/library/system.workflow.activities.listenactivity.aspx">ListenActivity</a> as its name suggests listens for incoming wake-up calls on the workflow. This activity idles the workflow, and waits for something to happen on one of its branches.</p>
<p>When this activity is dropped into the workflow designer two branches are automatically created (child activities), and these two are the minimum number of branches required to be defined. </p>
<p>On each branch we can only have <i>EventDriven</i> activities, because they are used to handle events; typically they can be raised from the host or by the runtime in response to a delay timer expiring. </p>
<p><b>Resume:</b></p>
<p>This activity is mostly used on scenarios where we want to wait for more than one event at the same time, or we want to set a timeout while waiting for some event to get raised.<b></b></p>
<p>Each branch is waiting for some event to occur before it can continue with the other activities on the branch. The first occurring event will be the one to run its branch activities first. All other branches cancel and stop listening for events. Basically, the ListenActivity blocks till one branch completes.<b></b></p>
<p><b>Example:</b></p>
<p>This example is based on a simple Sequential Workflow Console Application. As you can see in the following image, there are two branches on the Listen activity:</p>
<ul>
<li>The one on the left has a <i>HandleExternalEvent</i> activity (for more information about this activity please click <a href="http://blogit.create.pt/blogs/miguelisidoro/">here</a>) that is waiting for an external event to be raised (In this case for user to write its name on the console), and below is a <i>Code</i> activity that will display the user name and the current user number. </li>
<li>The right branch has a <i>Delay</i> activity that in this case will wait 15 seconds before raising a timeout event. If no external events are raised during the 15 seconds period, the right branch will be executed and a timeout message will be written. </li>
</ul>
<p><img decoding="async" src="http://pic40.picturetrail.com/VOL387/10929525/19439829/313608498.jpg"> </p>
<p>The following image shows an output where the following occurs:</p>
<ul>
<li>A first event is raised for a user named Lucas and the <i>Code</i> activity (Display_UserInput) on the <b>left</b> branch was executed; </li>
<li>A second event is raised for a user named Pipas and the <i>Code</i> activity on the left branch was executed again; </li>
<li>A timeout occurs. No events were raised for a period of 15 seconds and the <i>Code</i> activity (Display_Timeout_Msg) on the <b>right</b> branch was executed; </li>
<li>A third event is raised for a user named Miguel and the <b>left</b> branch activities were executed. </li>
</ul>
<p><img decoding="async" src="http://pic40.picturetrail.com/VOL387/10929525/19439829/313608499.jpg"> </p>
<p><b>Note:</b></p>
<p>The <a href="http://wiki.windowsworkflowfoundation.eu/default.aspx/WF/ListenActivity.html">ListenActivity</a> cannot be used in state machine workflows.</p>
<p>The post <a href="https://blogit.create.pt/tiagolucas/2008/04/17/windows-workflow-using-the-listenactivity/">Windows Workflow &#8211; Using the ListenActivity</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/tiagolucas/2008/04/17/windows-workflow-using-the-listenactivity/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Using WF CallExternalMethod activity in Windows Workflow</title>
		<link>https://blogit.create.pt/tiagooliveira/2008/04/16/using-wf-callexternalmethod-activity-in-windows-workflow/</link>
					<comments>https://blogit.create.pt/tiagooliveira/2008/04/16/using-wf-callexternalmethod-activity-in-windows-workflow/#respond</comments>
		
		<dc:creator><![CDATA[Tiago Oliveira]]></dc:creator>
		<pubDate>Wed, 16 Apr 2008 18:29:00 +0000</pubDate>
				<category><![CDATA[Windows Workflow Foundation]]></category>
		<category><![CDATA[Workflows]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/tiagooliveira/?p=121</guid>

					<description><![CDATA[<p>The CallExternalMethod Activity allows us to make synchronous communication between Workflow and the Host through the Local Service using Local Service Communication. Local Service Communication allows workflows to communicate with an external service that resides within the Host. Using this activity involves 4 phases: 1.&#160;&#160;&#160;&#160;Contract interface creation; 2.&#160;&#160;&#160;&#160;Workflow CallExternalMethod activity configuration with the contract interface, [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/tiagooliveira/2008/04/16/using-wf-callexternalmethod-activity-in-windows-workflow/">Using WF CallExternalMethod activity in Windows Workflow</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The <a href="http://msdn2.microsoft.com/en-us/library/system.workflow.activities.callexternalmethodactivity.aspx" target="_blank">CallExternalMethod Activity</a> allows us to make synchronous communication between Workflow and the Host through the Local Service<span style="color: red"><strong> </strong></span>using<strong> </strong>Local Service Communication. </p>
<p>Local Service Communication allows workflows to communicate with an external service that resides within the Host.<span style="font-size: 9pt;color: #0000dc;font-family: MS Shell Dlg"> </span></p>
<p>Using this activity involves 4 phases: </p>
<p>1.&nbsp;&nbsp;&nbsp;&nbsp;Contract interface creation; </p>
<p>2.&nbsp;&nbsp;&nbsp;&nbsp;Workflow CallExternalMethod activity configuration with the contract interface, the parameter(s) and return properties (if applies); </p>
<p>3.&nbsp;&nbsp;&nbsp;&nbsp;Contract implementation creation; </p>
<p>4.&nbsp;&nbsp;&nbsp;&nbsp;Using ExternalDataExchangeService class at the Host, to register the Contract implementation </p>
<p style="margin-left: 36pt">We can optionally set the input properties and read the return data. </p>
<p><strong>Example: </strong></p>
<p>In this example I&#039;m going to show the execution of a simple method that returns the 2 input parameters concatenation. </p>
<h3>1.&nbsp;&nbsp;&nbsp;&nbsp;Contract interface creation </h3>
<p>&nbsp;&nbsp;&nbsp;&nbsp;In the contract interface you have only to create the interface contract definition used by the Workflow. </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;You&#039;re going to create an Interface named &quot;IContract&quot;, which defines the Concatenate method. </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;All interfaces must have the <a href="http://msdn2.microsoft.com/en-us/library/system.workflow.activities.externaldataexchangeattribute.aspx" target="_blank">ExternalDataExchange</a> attribute defined that marks the interface as a local service interface. </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-size: 9pt;font-family: Consolas">[<span style="color: #2b91af">ExternalDataExchange</span>] </span><br /><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">public</span> <span style="color: blue">interface</span> <span style="color: #2b91af">IContract</span>&nbsp;<br />&nbsp;&nbsp;&nbsp; { </span><br /><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">string</span> Concatenate(<span style="color: blue">string</span> parameter1, <span style="color: blue">string</span> parameter2); </span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<h3>2.&nbsp;&nbsp;&nbsp;&nbsp;Workflow CallExternalMethodActivity configuration </h3>
<p>&nbsp;&nbsp;&nbsp;&nbsp;Add the CallExternalMethodActivity to the Workflow. </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;The Workflow will appear like this: </p>
<p><img fetchpriority="high" decoding="async" border="0" height="254" src="http://pic50.picturetrail.com/VOL460/10402378/18629414/311026231.jpg" style="width: 565px;height: 254px" width="565"></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;Then you will create three properties that correspond to the two input parameters to concatenate and the return concatenation. </p>
<p><span style="font-size: 9pt;font-family: Consolas"><span style="color: blue">&nbsp;&nbsp;&nbsp;&nbsp;public</span> <span style="color: blue">string</span> Parameter1ToConcat { <span style="color: blue">get</span>; <span style="color: blue">set</span>; } </span></p>
<p><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">public</span> <span style="color: blue">string</span> Parameter2ToConcat { <span style="color: blue">get</span>; <span style="color: blue">set</span>; } </span></p>
<p><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">public</span> <span style="color: blue">string</span> ConcatenateReturn { <span style="color: blue">get</span>; <span style="color: blue">set</span>; } </span></p>
<p><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp; </span></p>
<p><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;</span>Configure the CallExternalMethodActivity properties like this: </p>
<div style="margin-left: 30pt">
<table border="0" style="border-collapse: collapse">
<col span="1" style="width: 132px">
<col span="1" style="width: 397px">
<tbody valign="top">
<tr>
<td style="padding-right: 7px;padding-left: 7px;border: black 0.5pt solid">
<p><span style="font-size: 9pt;font-family: Consolas">InterfaceType</span></p>
</td>
<td style="border-right: black 0.5pt solid;padding-right: 7px;border-top: black 0.5pt solid;padding-left: 7px;border-left: medium none;border-bottom: black 0.5pt solid">
<p><span style="font-size: 9pt;font-family: Consolas">IContract interface</span></p>
</td>
</tr>
<tr>
<td style="border-right: black 0.5pt solid;padding-right: 7px;border-top: medium none;padding-left: 7px;border-left: black 0.5pt solid;border-bottom: black 0.5pt solid">
<p><span style="font-size: 9pt;font-family: Consolas">MethodName</span></p>
</td>
<td style="border-right: black 0.5pt solid;padding-right: 7px;border-top: medium none;padding-left: 7px;border-left: medium none;border-bottom: black 0.5pt solid">
<p><span style="font-size: 9pt;font-family: Consolas">Concatenate</span></p>
</td>
</tr>
<tr>
<td style="border-right: black 0.5pt solid;padding-right: 7px;border-top: medium none;padding-left: 7px;border-left: black 0.5pt solid;border-bottom: black 0.5pt solid">
<p><span style="font-size: 9pt;font-family: Consolas">Parameter1 &amp; parameter2</span></p>
</td>
<td style="border-right: black 0.5pt solid;padding-right: 7px;border-top: medium none;padding-left: 7px;border-left: medium none;border-bottom: black 0.5pt solid">
<p><span style="font-size: 9pt;font-family: Consolas">Parameter1ToConcat &amp; Parameter2ToConcat properties</span></p>
</td>
</tr>
<tr>
<td style="border-right: black 0.5pt solid;padding-right: 7px;border-top: medium none;padding-left: 7px;border-left: black 0.5pt solid;border-bottom: black 0.5pt solid">
<p><span style="font-size: 9pt;font-family: Consolas">(ReturnValue)</span></p>
</td>
<td style="border-right: black 0.5pt solid;padding-right: 7px;border-top: medium none;padding-left: 7px;border-left: medium none;border-bottom: black 0.5pt solid">
<p><span style="font-size: 9pt;font-family: Consolas">ConcatenateReturn property</span></p>
</td>
</tr>
</tbody>
</table>
</div>
<div style="margin-left: 30pt"></div>
<div style="margin-left: 30pt"></div>
<div style="margin-left: 30pt"></div>
<div style="margin-left: 30pt"></div>
<p><img decoding="async" border="0" height="244" src="http://pic50.picturetrail.com/VOL460/10402378/18629414/311026232.jpg" style="width: 548px;height: 244px" width="548">&nbsp; </p>
<h3>3.&nbsp;&nbsp;&nbsp;&nbsp;Contract implementation creation </h3>
<p>&nbsp;&nbsp;&nbsp;&nbsp;At the contract implementation creation, you have to create a class that implements IContract defined at the first step. </p>
<p><span style="font-size: 9pt;font-family: Consolas"><span style="color: blue">&nbsp; public</span> <span style="color: blue">class</span> <span style="color: #2b91af">ContractImplementation</span> : <span style="color: #2b91af">IContract</span> <br />&nbsp; {&nbsp;</span><br /><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">string</span> Concatenate(<span style="color: blue">string</span> parameter1, <span style="color: blue">string</span> parameter2)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;</span><br /><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> parameter1 + parameter2;&nbsp;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp; }</p>
<h3>4.&nbsp;&nbsp;&nbsp;&nbsp;Host configuration </h3>
<p>&nbsp;&nbsp;&nbsp;&nbsp;At the Host, the contract implementation is registered by using the <a href="http://msdn2.microsoft.com/en-us/library/system.workflow.activities.externaldataexchangeservice.aspx" target="_blank">ExternalDataExchangeService</a> class. </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;The input properties can be set by using the second parameter from the CreateWorkflow method. </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;The return parameter can be retrieved using the OutputParameters property from the WorkflowCompletedEventArgs class, at the WorkflowCompleted event. </p>
<p><span style="font-size: 9pt;font-family: Consolas"><span style="color: blue">using</span> (<span style="color: #2b91af">WorkflowRuntime</span> workflowRuntime = <span style="color: blue">new</span> <span style="color: #2b91af">WorkflowRuntime</span>()) </span><br />{&nbsp;<br /><span style="font-size: 9pt;font-family: Consolas"></span><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;&hellip;&nbsp;</span>&nbsp;<br /><span style="font-size: 9pt;font-family: Consolas"></span><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;workflowRuntime.WorkflowCompleted += <span style="color: blue">delegate</span>(</span> <br /><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">object</span> sender, <span style="color: #2b91af">WorkflowCompletedEventArgs</span> e)&nbsp;</span><br />&nbsp;&nbsp;&nbsp; {<br /><span style="font-size: 9pt;font-family: Consolas"><span style="color: #00b050">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// this is where we can get the return value</span></span>&nbsp;<br /><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #2b91af">Console</span>.Write((<span style="color: blue">string</span>)e.OutputParameters[<span style="color: purple">&quot;ConcatenateReturn&quot;</span>]);&nbsp;</span><br /><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;waitHandle.Set();</span> <br /><span style="font-size: 9pt;font-family: Consolas"></span>&nbsp;&nbsp;&nbsp; }&nbsp;<br /><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;</span><span style="font-size: 9pt;font-family: Consolas">&hellip;&nbsp;</span><br /><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;</span><span style="font-size: 9pt;font-family: Consolas"><span style="color: #2b91af">ExternalDataExchangeService</span> externalDataExchangeService = <span style="color: blue">new</span> <span style="color: #2b91af">ExternalDataExchangeService</span>();&nbsp;</span>&nbsp;</p>
<p><span style="font-size: 9pt;font-family: Consolas"><span style="color: #00b050">&nbsp;&nbsp;// add the external data exchange service to the runtime</span>&nbsp;</span><br /><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;workflowRuntime.AddService(externalDataExchangeService);&nbsp;</span></p>
<p><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;<span style="color: #00b050">// add the external method implementation to the local services&nbsp;</span></span><br /><span style="font-size: 9pt;color: #00b050;font-family: Consolas">&nbsp;&nbsp;// this is where we add the object(that implements IContract)</span><br /><span style="font-size: 9pt;color: #00b050;font-family: Consolas">&nbsp;&nbsp;// that is going to be invoked by the CallExternalMethodActivity&nbsp;</span><br /><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;externalDataExchangeService.AddService(<span style="color: blue">new</span> ContractProject.<span style="color: #2b91af">ContractImplementation</span>());&nbsp;</span></p>
<p><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;</span><span style="font-size: 9pt;font-family: Consolas"><span style="color: #2b91af">Dictionary</span>&lt;<span style="color: blue">string</span>, <span style="color: blue">object</span>&gt; parameters = <span style="color: blue">new</span> <span style="color: #2b91af">Dictionary</span>&lt;<span style="color: blue">string</span>, <span style="color: blue">object</span>&gt;();&nbsp;</span></p>
<p><span style="font-size: 9pt;font-family: Consolas"><span style="color: #00b050">&nbsp;&nbsp;// add&nbsp;both paramenters&nbsp;</span></span>&nbsp;<br /><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;parameters.Add(<span style="color: purple">&quot;Parameter1ToConcat&quot;</span>, <span style="color: purple">&quot;1&quot;</span>);</span>&nbsp;<br /><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;</span><span style="font-size: 9pt;font-family: Consolas">parameters.Add(<span style="color: purple">&quot;Parameter1ToConcat&quot;</span>, <span style="color: purple">&quot;2&quot;</span>);&nbsp;</span></p>
<p><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;</span><span style="font-size: 9pt;font-family: Consolas"><span style="color: #2b91af">WorkflowInstance</span> instance = workflowRuntime.CreateWorkflow(</span><br /><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue">typeof</span>(WorkflowConsoleApplication1.<span style="color: #2b91af">Workflow1</span>), parameters);&nbsp;</span><br /><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;</span><span style="font-size: 9pt;font-family: Consolas">instance.Start();&nbsp;</span><br /><span style="font-size: 9pt;font-family: Consolas">&nbsp;&nbsp;</span><span style="font-size: 9pt;font-family: Consolas">waitHandle.WaitOne();</span> <br /><span style="font-size: 9pt;font-family: Consolas">}&nbsp;</span></p>
<p>The post <a href="https://blogit.create.pt/tiagooliveira/2008/04/16/using-wf-callexternalmethod-activity-in-windows-workflow/">Using WF CallExternalMethod activity in Windows Workflow</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/tiagooliveira/2008/04/16/using-wf-callexternalmethod-activity-in-windows-workflow/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Windows Workflow &#8211; Using the HandleExternalEventActivity</title>
		<link>https://blogit.create.pt/miguelisidoro/2008/04/16/windows-workflow-using-the-handleexternaleventactivity/</link>
					<comments>https://blogit.create.pt/miguelisidoro/2008/04/16/windows-workflow-using-the-handleexternaleventactivity/#respond</comments>
		
		<dc:creator><![CDATA[Miguel Isidoro]]></dc:creator>
		<pubDate>Wed, 16 Apr 2008 11:09:54 +0000</pubDate>
				<category><![CDATA[Windows Workflow Foundation]]></category>
		<category><![CDATA[Workflows]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/miguelisidoro/?p=251</guid>

					<description><![CDATA[<p>Introduction This is the first in a series of blog posts dedicated to Windows Workflow. For those who don’t know, Windows Workflow Foundation (WF) is the new engine for building custom workflows (you can find more information about WF on the official web site). It was released as part of the .NET Framework 3.0 along [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/miguelisidoro/2008/04/16/windows-workflow-using-the-handleexternaleventactivity/">Windows Workflow &#8211; Using the HandleExternalEventActivity</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h5>Introduction</h5>
<p>This is the first in a series of blog posts dedicated to Windows Workflow. For those who don’t know, Windows Workflow Foundation (WF) is the new engine for building custom workflows (you can find more information about WF on the <a href="http://msdn.microsoft.com/winfx/technologies/workflow/default.aspx">official web site</a>). It was released as part of the .NET Framework 3.0 along with <a href="http://msdn2.microsoft.com/en-us/netframework/aa663326.aspx">Windows Presentation Foundation (WPF)</a> and <a href="http://msdn2.microsoft.com/en-us/netframework/aa663324.aspx">Windows Communication Foundation (WCF)</a>.</p>
<h5>Local Service Communication</h5>
<p>Workflows are not isolated entities and most of the times need to communicate with the outside world in order to perform some task. There are several ways of communicating with external entities/services, being one of them External Data Exchange and Local Service Communication. Local Service Communication basically allows workflows to communicate with an external service that resides within the workflow host. There are two main activities inside WF that allow communication between a workflow and an external service using Local Service Communication:</p>
<ul>
<li><strong>CallExternalMethodActivity</strong> – Allows a workflow to call a method from an external service. The workflow and the host establish a contract (using an interface) that defines the way they communicate with each other. Basically the workflow calls a method of a service residing within the host that implements the contract interface. For more details about this activity, click <a href="http://blogit.create.pt/blogs/tiagooliveira/archive/2008/04/16/Using-WF-CallExternalMethod-activity-in-Windows-Workflow.aspx" target="_blank" rel="noopener noreferrer">here</a>.</li>
<li><b>HandleExternalEventActivity</b> – Besides allowing the workflow to call an external method, it is also possible for the host to send an event to the workflow in order for it to perform some task. This is achieved using the HandleExternalEventActivity that will put the workflow on an idle state until an external event is raised. Just as in CallExternalMethodActivity, the communication between the workflow and the external is based on a contract.</li>
</ul>
<h5></h5>
<h5>Summary</h5>
<p>To build a workflow that uses HandleExternalEventActivity to communicate with a service using Local Service Communication, you’ll need to:</p>
<ul>
<li>Define a contract (interface);</li>
<li>Implement a service based on the defined contract;</li>
<li>Develop a workflow that uses HandleExternalEventActivity;</li>
<li>Develop a host for the workflow;</li>
<li>Add the service to the workflow runtime in the host;</li>
<li>Start the workflow and handle the workflow WorkflowIdled event in the host;</li>
<li>Raise the event.</li>
</ul>
<h5></h5>
<h5>Example</h5>
<p>As already explained, the HandleExternalEventActivity allows communication between a workflow and an external service using Local Service Communication based on event notifications. Next, I will present a simple demo that will show a very basic usage of this activity. The demo is based on a simple Approval State Machine Workflow Console Application. The console application will ask the user if he/she wants to approve and based on the answer it will pass the corresponding answer to the workflow through the raise of an event. This is how the workflow looks like:</p>
<p><img decoding="async" src="http://pic90.picturetrail.com/VOL2147/10903553/19399056/312016167.jpg" /></p>
<p>This workflow will basically handle the external event inside the <i>StartState</i> activity and set the approved or rejected state according to the information supplied by the host in the event. The interface of the service is defined like this:</p>
<pre class="code">[<span style="color: #2b91af">ExternalDataExchange</span>]
<span style="color: blue">public interface </span><span style="color: #2b91af">IApprovalEventService
</span>{
    <span style="color: blue">void </span>RaiseSetStateEvent(<span style="color: #2b91af">Guid </span>instanceId, <span style="color: blue">bool </span>approve);

    <span style="color: blue">event </span><span style="color: #2b91af">EventHandler</span>&lt;<span style="color: #2b91af">ApprovalExternalDataEventArgs</span>&gt; ExternalDataEvent;
    
}</pre>
<p>The interface uses the <a href="http://msdn2.microsoft.com/en-us/library/system.workflow.activities.externaldataexchangeattribute.aspx" target="_blank" rel="noopener noreferrer">ExternalDataExchange</a> attribute which allows the workflow to use it to communicate with the host using Local Service Communication. The interface defines the event, whose arguments are of type ApprovalExternalDataEventArgs, a type derived from ExternalEventArgs. It also defines a RaiseSetStateEvent method that will be used by the host to raise the event. This method defines an additional Boolean parameter named <i>approve</i> in order to pass the approval information to the workflow. This is how the ApprovalExternalDataEventArgs class looks like:</p>
<pre class="code">[<span style="color: #2b91af">Serializable</span>]
<span style="color: blue">public class </span><span style="color: #2b91af">ApprovalExternalDataEventArgs </span>: <span style="color: #2b91af">ExternalDataEventArgs
</span>{
    <span style="color: blue">private bool </span>_result;

    <span style="color: blue">public bool </span>Result {
        <span style="color: blue">set </span>{
            _result = <span style="color: blue">value</span>; 
        }
        <span style="color: blue">get </span>{
            <span style="color: blue">return </span>_result;
        }
    }

    <span style="color: blue">public </span>ApprovalExternalDataEventArgs(<span style="color: #2b91af">Guid </span>instanceId, <span style="color: blue">bool </span>approve)
        : <span style="color: blue">base</span>(instanceId) {
        Result = approve;
    }
}</pre>
<p>In the constructor, a Boolean <i>approve</i> parameter is used. This parameter is populated by the host when raising the event and is used to set the Result property that will be used later by the workflow. The other parameter used in the constructor is <i>instanceId</i>, which is used to correlate the event with the right workflow instance.</p>
<p>The HandleExternalEventActivity is defined inside the <i>StartState</i> activity and is named <i>handleSetState</i>. Here are the details of the <i>StartState</i> activity:</p>
<p><img decoding="async" src="http://pic90.picturetrail.com/VOL2147/10903553/19399056/312016166.jpg" /></p>
<p>As shown in the image above, the external event is handled by the HandleExternalEventActivity <i>handleSetState.</i> Then, based on the value that was supplied by the host, approval or rejected activities will be executed (in this case a simple message will be written to the application console). The properties for the HandleExternalEventActivity <i>handleSetState</i> look like this:</p>
<p><img decoding="async" src="http://pic90.picturetrail.com/VOL2147/10903553/19399056/313494752.jpg" /></p>
<p>There are three properties worth mentioning here:</p>
<ul>
<li><b>e</b> – It will hold the event arguments for the workflow instance. In this case it is set to <i>ExternalDataEvent</i>, a public property in the workflow of type ApprovalExternalDataEventArgs.</li>
<li><b>EventName</b> – name of the event that will be handled. Also set to <i>ExternalDataEvent.</i><b></b></li>
<li><b>InterfaceType</b> – name of the interface. Set to IApprovalEventService.</li>
</ul>
<p>The IfElseActivity defined after the HandleExternalEventActivity will evaluate a code condition to determine whether to execute the Approve or Reject activities.</p>
<p><img decoding="async" src="http://pic90.picturetrail.com/VOL2147/10903553/19399056/312025688.jpg" /></p>
<p>The code condition is based on a CheckState method that will verify the Result property of the workflow ExternalDataEvent property.</p>
<pre class="code"><span style="color: green">// Code condition to evaluate whether to take the 1st branch, YesIfElseBranch
// Since it always returns true, the 1st branch is always taken.
</span><span style="color: blue">private void </span>CheckState(<span style="color: blue">object </span>sender, <span style="color: #2b91af">ConditionalEventArgs </span>e) {
    e.Result = ExternalDataEvent.Result;
}</pre>
<p>The two remaining pieces of this demo are the service and the host console application. Here is the definition of the service:</p>
<pre class="code"><span style="color: blue">class </span><span style="color: #2b91af">ApprovalEventService </span>: <span style="color: #2b91af">IApprovalEventService
</span>{
    <span style="color: blue">#region </span>IApprovalEventService Members

    <span style="color: blue">public void </span>RaiseSetStateEvent(<span style="color: #2b91af">Guid </span>instanceId, <span style="color: blue">bool </span>approve)
    {
        <span style="color: green">// create event
        </span><span style="color: #2b91af">EventHandler</span>&lt;<span style="color: #2b91af">ApprovalExternalDataEventArgs</span>&gt; setStateEvent 
        = <span style="color: blue">this</span>.ExternalDataEvent;

        <span style="color: green">// launch event
        </span><span style="color: blue">if </span>(setStateEvent != <span style="color: blue">null</span>)
            setStateEvent(<span style="color: blue">null</span>, <span style="color: blue">new </span><span style="color: #2b91af">ApprovalExternalDataEventArgs
                </span>(instanceId, approve));
    }

    <span style="color: blue">public event </span><span style="color: #2b91af">EventHandler</span>&lt;<span style="color: #2b91af">ApprovalExternalDataEventArgs</span>&gt; 
        ExternalDataEvent;
   

    <span style="color: blue">#endregion
</span>}</pre>
<p>The console application code looks like this:</p>
<pre class="code"><span style="color: blue">private static </span><span style="color: #2b91af">ApprovalEventService </span>service;
<span style="color: blue">private static </span><span style="color: #2b91af">Guid </span>instanceId; 

<span style="color: gray">/// &lt;summary&gt;
/// </span><span style="color: green">We've decorated the IEventService interface with the 
</span><span style="color: gray">/// </span><span style="color: green">ExternalDataExchangeAttribute.
</span><span style="color: gray">/// </span><span style="color: green">The event args class (ApprovalExternalDataEventArgs) 
</span><span style="color: gray">/// </span><span style="color: green">derives from ExternalDataEventArgs.
</span><span style="color: gray">/// </span><span style="color: green">The event args class (ApprovalExternalDataEventArgs) is serializable.
</span><span style="color: gray">/// </span><span style="color: green">ApprovalEventService implements IEventService.
</span><span style="color: gray">/// &lt;/summary&gt;
/// &lt;param name="args"&gt;&lt;/param&gt;
</span><span style="color: blue">static void </span>Main(<span style="color: blue">string</span>[] args)
{
    <span style="color: blue">using</span>(<span style="color: #2b91af">WorkflowRuntime </span>workflowRuntime = <span style="color: blue">new </span><span style="color: #2b91af">WorkflowRuntime</span>())
    {
        <span style="color: green">//add ApprovalEventService service to the workflow runtime
        </span><span style="color: #2b91af">AutoResetEvent </span>waitHandle = <span style="color: blue">new </span><span style="color: #2b91af">AutoResetEvent</span>(<span style="color: blue">false</span>);
        <span style="color: #2b91af">ExternalDataExchangeService </span>dataExchange = 
        <span style="color: blue">new </span><span style="color: #2b91af">ExternalDataExchangeService</span>();
        workflowRuntime.AddService(dataExchange);
        service = <span style="color: blue">new </span><span style="color: #2b91af">ApprovalEventService</span>();
        dataExchange.AddService(service);
        
        workflowRuntime.WorkflowCompleted += 
        <span style="color: blue">delegate</span>(<span style="color: blue">object </span>sender, <span style="color: #2b91af">WorkflowCompletedEventArgs </span>e) 
        {
            <span style="color: green">//display workflow completion message
            </span><span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">"Workflow completed."</span>);
            waitHandle.Set();
        };
        workflowRuntime.WorkflowTerminated += 
        <span style="color: blue">delegate</span>(<span style="color: blue">object </span>sender, <span style="color: #2b91af">WorkflowTerminatedEventArgs </span>e)
        {
            <span style="color: green">//display error message if an exception is raised
            </span><span style="color: #2b91af">Console</span>.WriteLine(e.Exception.Message);
            waitHandle.Set();
        };
        workflowRuntime.WorkflowIdled += 
        <span style="color: blue">delegate</span>(<span style="color: blue">object </span>sender, <span style="color: #2b91af">WorkflowEventArgs </span>e)
        {
            <span style="color: green">//read the input from keyboard (yes/no) and raise 
            //the event passing the answer as a boolean parameter
            </span><span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">"Workflow idled."</span>);
            <span style="color: #2b91af">Console</span>.Write(<span style="color: #a31515">"Do you want to approve? (Y/N) "</span>);
            <span style="color: blue">string </span>key = <span style="color: #2b91af">Console</span>.ReadLine();
            <span style="color: blue">bool </span>approved = key.ToLower() == <span style="color: #a31515">"y" </span>? <span style="color: blue">true </span>: <span style="color: blue">false</span>;
            <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">"Sending event to workflow."</span>);
            service.RaiseSetStateEvent(instanceId, approved);
        };

        <span style="color: green">//start workflow
        </span><span style="color: #2b91af">WorkflowInstance </span>instance = 
        workflowRuntime.CreateWorkflow(
        <span style="color: blue">typeof</span>(StateMachineCommunicationDemo.<span style="color: #2b91af">SimpleStateMachine</span>));
        instanceId = instance.InstanceId;
        <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">"Starting workflow."</span>);
        instance.Start();

        <span style="color: green">//put workflow in an idle state
        </span>waitHandle.WaitOne();

        <span style="color: green">//stop runtime
        </span>workflowRuntime.StopRuntime();

        <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">"Press any key."</span>);
        <span style="color: #2b91af">Console</span>.Read();
    }
}</pre>
<p>In the code above, the following actions are performed:</p>
<ul>
<li>The service is added to the workflow runtime. In order for the service to be correctly added to runtime, two AddService methods must be executed and in the right order. First, an instance of ExternalDataExchangeService is added to the workflow runtime. Then, an instance of our service (ApprovalEventService) is added to the <a href="http://msdn2.microsoft.com/en-us/library/system.workflow.activities.externaldataexchangeservice.aspx" target="_blank" rel="noopener noreferrer">ExternalDataExchangeService</a> instance.</li>
<li>The workflow is started</li>
<li>The workflow is placed in an idle state</li>
<li>Several delegate functions are defined to handle workflow events. The most important one is the event handler for the WorkflowIdled event. The event handler will be trigger once the workflow is placed in an idle state. Then, the user will be asked the approval question and the event is raised which will cause the HandleExternalEventActivity in the workflow to be executed.</li>
</ul>
<p>Here is the application’s output in case of approval:</p>
<p><img decoding="async" src="http://pic90.picturetrail.com/VOL2147/10903553/19399056/313495367.jpg" /></p>
<p>And in case of rejection:</p>
<p><img decoding="async" src="http://pic90.picturetrail.com/VOL2147/10903553/19399056/313495369.jpg" /></p>
<p>Another related activity is the ListenActivity. For more information, please click <a href="http://blogit.create.pt/blogs/tiagolucas/archive/2008/04/17/Windows-Workflow-_2D00_-Using-the-ListenActivity.aspx" target="_blank" rel="noopener noreferrer">here</a>.</p>
<h1>Related Articles</h1>
<p>To learn why your business should migrate to SharePoint Online and Office 365, click <a href="https://blogit.create.pt////miguelisidoro/2019/07/29/why-your-business-should-migrate-to-sharepoint-online-and-office-365-the-value-offer-part-1/" target="_blank" rel="noreferrer noopener">here</a> and <a href="https://blogit.create.pt////miguelisidoro/2019/07/29/why-your-business-should-migrate-to-sharepoint-online-and-office-365-the-value-offer-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you want to convert your tenant&#8217;s root classic site into a modern SharePoint site, click <a href="https://blogit.create.pt////miguelisidoro/2019/08/27/how-to-modernize-your-tenant-root-site-collection-in-office-365-using-invoke-spositeswap/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you are a SharePoint administrator or a SharePoint developer who wants to learn more about how to install a SharePoint farm in an automated way using PowerShell, I invite you to click <a href="https://blogit.create.pt////miguelisidoro/2018/07/28/how-to-install-a-sharepoint-2016-farm-using-powershell-and-autospinstaller-part-1/" target="_blank" rel="noopener noreferrer">here</a> and <a href="https://blogit.create.pt////miguelisidoro/2018/07/28/how-to-install-a-sharepoint-2016-farm-using-powershell-and-autospinstaller-part-2/" target="_blank" rel="noopener noreferrer">here</a>. The articles use AutoSPInstaller with a SharePoint 2016 farm but AutoSPInstaller support for SharePoint 2019 was already announced!</p>
<p>If you want to learn how to upgrade a SharePoint 2013 farm to SharePoint 2019, click <a href="https://blogit.create.pt////miguelisidoro/2019/03/06/how-to-upgrade-from-sharepoint-2013-to-sharepoint-2019-step-by-step-part-1/" target="_blank" rel="noreferrer noopener">here </a>and <a href="https://blogit.create.pt////miguelisidoro/2019/03/06/how-to-upgrade-from-sharepoint-2013-to-sharepoint-2019-step-by-step-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you want to learn all the steps and precautions necessary to successfully keep your SharePoint farm updated and be ready to start your move to the cloud, click <a href="https://blogit.create.pt////miguelisidoro/2019/04/08/how-to-install-sharepoint-cumulative-updates-in-a-sharepoint-farm-step-by-step/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you learn how to greatly speed up your SharePoint farm update process to ensure your SharePoint farm keeps updated and you stay one step closer to start your move to the cloud, click <a href="https://blogit.create.pt////miguelisidoro/2019/05/02/how-to-speed-up-the-installation-of-sharepoint-cumulative-updates-using-powershell-step-by-step/" target="_blank" rel="noreferrer noopener" aria-label="here (opens in a new tab)">here</a>.</p>
<p>If you want to learn how to upgrade a SharePoint 2010 farm to SharePoint 2016, click <a href="https://blogit.create.pt////miguelisidoro/2019/02/04/sharepoint-upgrade-upgrading-a-sharepoint-2010-farm-to-sharepoint-2016-step-by-step-part-1/" target="_blank" rel="noreferrer noopener">here </a>and <a href="https://blogit.create.pt////miguelisidoro/2019/02/04/sharepoint-upgrade-upgrading-a-sharepoint-2010-farm-to-sharepoint-2016-step-by-step-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>If you are new to SharePoint and Office 365 and want to learn all about it, take a look at these <a href="https://blogit.create.pt////miguelisidoro/2018/10/17/sharepoint-and-office-365-learning-resources/" target="_blank" rel="noopener noreferrer">learning resources</a>.</p>
<p>If you are work in a large organization who is using Office 365 or thinking to move to Office 365 and is considering between a single or multiple Office 365 tenants, I invite you to read <a href="https://blogit.create.pt////miguelisidoro/2019/01/07/pros-and-cons-of-single-tenant-vs-multiple-tenants-in-office-365/" target="_blank" rel="noreferrer noopener">this article</a>.</p>
<p>If you or your customers are not ready to move entirely to the Cloud and Office 365, a hybrid scenario could be an interesting scenario and SharePoint 2019 RTM was recently announced with improved hybrid support! To learn all about SharePoint 2019 and all its features, click <a href="https://blogit.create.pt////miguelisidoro/2018/11/01/meet-the-new-modern-sharepoint-server-sharepoint-2019-rtm-is-here/" target="_blank" rel="noopener noreferrer">here</a>.</p>
<p>If you want to know all about the latest SharePoint and Office 365 announcements from SharePoint Conference 2019, click <a href="https://blogit.create.pt////miguelisidoro/2019/06/05/whats-new-for-sharepoint-and-office-365-from-sharepoint-conference-2019-part-1/" target="_blank" rel="noreferrer noopener">here </a>and <a href="https://blogit.create.pt////miguelisidoro/2019/06/05/whats-new-for-sharepoint-and-office-365-from-sharepoint-conference-2019-part-2/" target="_blank" rel="noreferrer noopener">here</a>.</p>
<p>Happy SharePointing!</p>
<p>The post <a href="https://blogit.create.pt/miguelisidoro/2008/04/16/windows-workflow-using-the-handleexternaleventactivity/">Windows Workflow &#8211; Using the HandleExternalEventActivity</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/miguelisidoro/2008/04/16/windows-workflow-using-the-handleexternaleventactivity/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
