With our pluggable workflow service and external calculation engine up and running, we can create a basic workflow in Visual Studio that will send messages to the calculation engine. Our test workflow will be very simple; when a new item is added to a list, its title will be sent to the calculation engine. We will then be able to trigger a response manually from the calculation engine, which will be passed to the workflow. The workflow will log the response and complete.
Using the Visual Studio Workflow Designer
When the workflow has been added to the project, the workflow designer tool will be displayed. You can see that its user interface is similar to the one we created earlier using Visio 2010. You can drag workflow activities from the toolbox on to the design surface to build up the workflow logic.
Our workflow needs five additional steps: CallExternalMethod, which can be found in the Windows Workflow v3.0 group in the toolbox; SetState, which can be found in the SharePoint Workflow group; HandleExternalEvent, which can be found in the Windows Workflow v3.0 group; LogToHistoryListActivity, which can be found in the SharePoint Workflow group; and CodeActivity, which can be found in the Windows Workflow v3.0 group. Drag the required activities onto the designer surface, as illustrated:
Configuring Workflow Activities
You can see from the designer that a few of our activities have not been configured properly. This is indicated by the icon in the upperright corner of the activity control. Let’s work through them in sequence to set the appropriate configuration details. CallExternalMethodActivity Starting with callExternalMethodActivity1, when we select the activity we can see in the Properties pane that the values for InterfaceType and MethodName are invalid as shown. This activity is used to communicate with a pluggable workflow service and in our case will be used to invoke the SubmitCalculation method on our CalculationWorkflowService.
SetStateActivity and CorrelationTokens Moving onto the setState1 activity, we can see that the CorrelationToken property is invalid. CorrelationTokens are an important aspect of WF workflows and are used to determine the scope of the activity. A CorrelationToken is simply a text value that is used to group activities and, more importantly, the properties that they use. If a workflow has a property named foo, for example, when a workflow activity with a correlation token of token A writes to the foo property, other workflow actions with a correlation token of token A will be able to read the value. However, if a workflow action with a correlation token of token B writes to the property, the actions with a token of token A will still see the original value, whereas actions with token B will see the new value. In effect, every property is actually an array with the correlation token being used as an indexer. When it comes to SharePoint workflows, this is particularly relevant when using Task activities. Set the CorrelationToken for setState1 to workflowToken with an OwnerActivityName of External_Calculation.
Adding Custom Status Values to SharePoint Although the configuration of the setState activity is now valid, it doesn’t quite do what we want it to. When a workflow is added to a list item in SharePoint, a new column is added to the appropriate list that shows the current state of the workflow. The setState activity allows us to specify the value that should appear in this list. In our case, we want to show the text Awaiting Calculation Result. Before we can display a custom value for workflow status, we need to let SharePoint know what our new value is. Workflow states are stored in SharePoint in a similar format to lookup values, so each state needs an ID and a text value. To add new states, we need only the text value, since SharePoint will automatically generate a new ID. We can add the text for the new state in the Elements.xml file that exists under our External Calculation workflow in the Solution Explorer pane. Add an ExtendedStatusColumnValues element to the MetaData element, as shown:<MetaData><AssociationCategories>List</AssociationCategories><StatusPageUrl>_layouts/WrkStat.aspx</StatusPageUrl><ExtendedStatusColumnValues><StatusColumnValue>Awaiting Calculation Result</StatusColumnValue></ExtendedStatusColumnValues></MetaData>
With the text value for our new status added, we can now configure our setState activity to use it. Unfortunately, it’s not quite as simple as that though. SetState expects the ID of our new state, and since this will be generated by SharePoint when our workflow is installed, we don’t currently have a reference to the ID value. We can calculate the ID for our new state simply by adding one to the ID of the last state that SharePoint defines internally.
public int AwaitingCalculationState = ((int) SPWorkflowStatus.Max);
SPWorkflowStatus is an enumeration of the workflow states that SharePoint provides by default. Our new extended status column value will be assigned the next ID in the sequence, which we can retrieve using the SPWorkflowStatus.Max value. If we wanted to add more than one additional state, we could use SPWorkflowStatus.Max +1, SPWorkflowStatus.Max+2, and so on, to determine the IDs for subsequent states.
LogToHistoryListActivity We’ve now configured all the mandatory properties for our workflow. Before we deploy, we need to make one additional change. The logToHistoryListActivity1 action is not set up to log anything useful to the workflow history list. Since we want it to pick up the calculation result, we need to set a few properties.
CodeActivity The CodeActivity can be used to execute arbitrary code within the workflow engine. Our workflow requires that, as a result of the external calculation process, the Environmental Compliance flag is set to true or false. For the purposes of our demonstration, we’ll assume that our organization manufactures only environmentally friendly products and that the result of the calculation always indicates compliance.
We’ve now completed our test workflow. When deploying the solution to SharePoint, our workflow will automatically be attached to the Product list With our DemoCalculationEngine project running, we can add new items to the Product list and see the messages being passed to our calculation engine as expected. Viewing the workflow history will also show that the status value is being updated as expected and the calculation result is being written to history before the workflow completes.
Share Point 2010 Related Interview Questions
|Web Services Interview Questions||XML Interview Questions|
|Share Point 2010 Interview Questions||ASP.NET Interview Questions|
|Share Point Administration Interview Questions||BizTalk Admin Interview Questions|
|Microsoft Office SharePoint Server (MOSS) Interview Questions||Biztalk Server Interview Questions|
|Asp Dot Net Mvc 4 Interview Questions||Biztalk Esb Toolkit Interview Questions|
|InfoPath Interview Questions|
Share Point 2010 Tutorial
The Microsoft Sharepoint 2010 Platform
Developing With Sharepoint 2010
Presentation Layer Overview
Client Object Model
Infopath Forms Services
Enterprise Content Management
User Interface Customization
Application Services Overview
Service Application Framework
Word Automation Services
Data Access Overview
Linq To Sharepoint And Spmetal
Business Connectivity Services
User Profiles And Social Data
Packaging And Deployment Model
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.