SharePoint 2010: Full Trust Custom Workflow Activities

Before moving on to some real action let’s get familiar with some of the facts on Activity:

  • An activity is a portion of work that is completed with the help of other resources.
  • Activities are the basic building blocks of workflows.
  • A workflow can be created by using a single activity or a group of activities. SharePoint 2010 enables both out-of-the-box and custom activities.
  • Out-of-the-box activities can be used directly in Microsoft SharePoint Designer 2010; custom activities require some coding.

Now let’s see some facts on Custom Code Activity With a wide selection of out-of-the-box activities, why are custom activities needed at all? This question is especially relevant when you consider that it is also fairly easy to execute code in an existing workflow by adding a CodeActivity and then writing the code in the ExecuteCode event handler. However, custom activities are especially helpful because they wrap custom code in a reusable component. Further, as the following examples show, some essential actions require more functionality than out-of-the-box activities can provide.

  • Looping: Out-of-the-box activities cannot provide direct looping support through collections, such as the lists in a site or the items in a list.
  • Accessing outside content: With out-of-the-box activities, it is not possible to access SharePoint content in other sites or site collections or to access anything at the farm or web application level.
  • Calling across the network: Standard actions do not support calling a remote web service from a SharePoint Designer 2010 workflow.
  • Running with elevated permissions: Out-of-the-box activities run under the current user’s identity and permissions. Although Impersonation steps can help mitigate this, workflow actions are still restricted from running under a more privileged user’s identity and elevated permissions.
  • Obtaining control at the workflow level: By its nature, SharePoint Designer 2010 insulates the workflow builder from the details of the underlying SharePoint workflow architecture.

Enough of the theory for now. Now it’s time to see some action. Steps to Implement Custom Activity:

  • Add a new project using class library project template

1

  • Add new workflow activity as shown below

2 3

  • Add code to the activity as shown below

4 5 Now we will do some investigation on each property and functions used in this code.

  • Dependency properties indicate that the workflow depends on this value. All values that are used as inputs or outputs for the custom workflow activity should be marked as dependency properties. Following are the available dependency properties in our code:
    1. SiteUrlProperty: This property maps with SiteUrl Browsable Property.
    2. ListINameProperty: This property maps with ListName Browsable Property.
    3. ListTemplateProperty: This property maps with ListTemplate Browsable Property.
  • Browsable Properties are the simple properties decorated with a number of Attributes. Browsable Properties must be mapped with corresponding Dependency Properties. Following are the available Browsable Properties in our code:
  1. SiteUrl
  2. ListName
  3. ListTemplate
  • Execute Method: The Execute method must complete by returning a value from the ActivityExecutionStatus enumeration. Enumeration of activity status values corresponds to the life cycle of an activity in a running workflow instance. Once execution of the code is complete, you must call the enumeration Closed for the activity. The following table shows different enumerations for custom activities:

6

  • CreateList Method: This is just a simple helper function which creates the SharePoint List using server side object model.

And that’s the end of our analysis. Now lets continue with the remaining steps

  • Add Strong Name Key to the Project by going to the Project Properties > Signing Tab  as shown below:

7

  • Build the solution

Steps to Implement Custom Activity Deployment Project:

  • Add Empty SharePoint Project as shown below:

8

  • Add the reference of CustomWorkflowActivties.dll in this solution
  • Add SharePoint Mapped Folder TEMPLATE\1033\Workflow
  • Add xml file with the name CreateListWorkflowActivity.Actions, make sure this file must have the .Actions extension otherwise SharePoint Runtime would not get it recognized as an workflow action.
  • Add the configuration entries to the CreateListWorkflowActivity.Actions file as shown below:

9

  • Add AuthorizedType entry to Web.config file of Web Application for this custom workflow action, else it won’t get displayed in SharePoint Designer > Workflows > Action ribbon menu

Note: To make a full-trust workflow activity available to declarative workflows, add an authorizedType entry to the Web.config file for the content web application. This gives your custom activity the same status as the built-in workflow activities that are included with SharePoint 2010. The following code example shows the format of an authorizedType entry. 10

  • Build the solution
  • Deploy the solution

And with this we are done with our development work, now it is the time to test our efforts. Steps to test Custom Activity:

  • Launch SharePoint Designer
  • Connect to SharePoint Site
  • Click on left navigation link “Workflows”

11

  • Click on Site Workflows in the ribbon. Enter Name and Description for the workflow.

12 13

  • Choose Action Menu > Custom Workflow Activities > Create SharePoint List Action

14

  • Configure Create SharePoint List Action by providing following information
  1. List Name
  2. Site Url
  3. List Template

15

  • The activity will look like as below after configuration

16

  • Save the Workflow by selecting Save option in the ribbon

17

  • Check for the errors in Workflow before publishing it by selecting Check for Errors option in the ribbon
  • Publish the Workflow by selecting Publish option in the ribbon
  • Navigate to the SharePoint Site
  • Click Site Settings > View All Site Content

18

  • Click on Site Workflows Link

19

  • Start the workflow

20 21 22

  • On completion of Workflow, go to View Site Content > Lists, and you should be able to see the new list of type Announcement

24 Hope this will help someone in need…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s