WEBSITE

Sharepoint 2010 : Creating a Workflow Using Visual Studio 2010 - Using the Visual Studio Workflow Designer (part 2)

11/4/2013 3:09:38 AM
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.

  1. Right-click the workflow designer and then select View Code to see the code behind for our workflow. Add the following field:

    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.

  2. We can now bind the State property of our SetState activity to our new AwaitingCalculationState field.

HandleExternalActivity

The next activity to configure is handleExternalEventActivity1. This activity listens for an event from a pluggable workflow service. It’s configured in much the same way as callExternalMethodActivity1.

  1. Set the InterfaceType to IExternalCalculationService, and then select CalculationComplete from the EventName drop-down.

  2. Since this is an event, we don’t need to specify any parameters. Although, since we’re interested in the CalculationResultArgs parameter that is passed with the event, we can bind this value to a local variable using the e property. Click the ellipsis to show the Bind dialog. This time, select the Bind To New Member tab and then add a new property with the name CalculationCompleteArgs, as shown. This binding will store the values passed with the event in a local variable called CalculationCompleteArgs that we’ll be able to use in subsequent workflow activities.

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.

  1. For HistoryOutcome, type Calculation Result.

  2. Using the Bind dialog, bind the HistoryDescription property to CalculationCompleteArgs.Result, as shown:

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.

  1. To configure the CodeActivity for the ExecuteCode property, enter UpdateFlag.

  2. Press enter, and the designer switches to code-behind view and a new method is automatically created for UpdateFlag. Add the following code:

    private void UpdateFlag(object sender, EventArgs e)
    {
    workflowProperties.Item["Environmental Compliance"] = true;
    workflowProperties.Item.Update();
    }
Other  
  •  Sharepoint 2010 : Creating a Pluggable Workflow Service (part 6) - Calling a SharePoint-Hosted WCF Service
  •  Sharepoint 2010 : Creating a Pluggable Workflow Service (part 5) - Calling a WCF Service, Receiving WCF Messages , Raising Events in a Workflow Service, Configuring Pluggable Workflow Services
  •  Sharepoint 2010 : Creating a Pluggable Workflow Service (part 4) - Using the ExternalDataExchange Attribute, Deriving from SPWorkflowExternalDataExchangeService
  •  Sharepoint 2010 : Creating a Pluggable Workflow Service (part 3) - Hosting an .svc File in SharePoint, Token Replacement in Visual Studio , Adding WCF Service Configuration to SharePoint
  •  Sharepoint 2010 : Creating a Pluggable Workflow Service (part 2) - Add a SharePoint-Hosted WCF Service
  •  Sharepoint 2010 : Creating a Pluggable Workflow Service (part 1) - Create a Windows Forms Client Hosting a WCF Service
  •  PowerShell for SharePoint 2013 : Word Automation Services - Disable Word 97–2003 Document Scanning , Disable Embedded Fonts in Conversions
  •  PowerShell for SharePoint 2013 : Word Automation Services - Modify Job Monitoring, Modify Conversion Timeouts
  •  PowerShell for SharePoint 2013 : Word Automation Services - Configure Supported Document Formats for Conversion, Modify Database Information
  •  PowerShell for SharePoint 2013 : Word Automation Services - Configure the Conversion Processes, Configure Conversion Throughput
  •  
    Top 10
    Review : Sigma 24mm f/1.4 DG HSM Art
    Review : Canon EF11-24mm f/4L USM
    Review : Creative Sound Blaster Roar 2
    Review : Philips Fidelio M2L
    Review : Alienware 17 - Dell's Alienware laptops
    Review Smartwatch : Wellograph
    Review : Xiaomi Redmi 2
    Extending LINQ to Objects : Writing a Single Element Operator (part 2) - Building the RandomElement Operator
    Extending LINQ to Objects : Writing a Single Element Operator (part 1) - Building Our Own Last Operator
    3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    VIDEO TUTORIAL
    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
    Popular Tags
    Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8