Changes in SharePoint DesignerTypes for workflow activity parameters

Creating a workflow in SharePoint Designer consists of selecting Conditions and Activities to build the logic and determine what actions the workflow performs. When you select an activity or condition a sentence appears in the WorkFlow Designer screen with underlined phrases that allow you click on them to set the workflow’s parameters. These parameters can be selecting a column on a list item and a value to give it, or they can be a user’s account name, a url to a site or something more complex like an email definition that includes a To address, CC address, a subject and a body.

When creating custom workflow activities and conditions for SharePoint in Visual Studio, you create a code class to build its functionality as well as a .actions file, both of which define the parameters. SharePoint Designer uses the .actions to be able to add the activity or condition to a workflow. You must specify the type for each parameter within both the class and the .actions file as well as the DesignerType in the .actions file. When a user clicks on a parameter, different windows open to allow the user to input the values according to the DesignerType given to the parameter. The DesignerType is simply an enumeration that SharePoint Designer uses to determine what type of form to display to gather information on each parameter. For example, a DesignerType of DropDown will present a drop down menu at the location of the parameter phrase in the sentence, whereas a DesignerType of Email will open a pop up window with fields for the To address, CC address, Subject and Body where each of these fields is defined as a parameter of different types in code and returned from the Designer form as an object of that type.

For an activity to send an email, the simple class definition may look something like this:

In terms of SharePoint 2010, there are several new DesignerTypes and some of the existing ones have changed slightly in the types of parameters that they return. Below is an overview of most, if not all, of the DesignerTypes included in 2010.

Designer Type

New to 2010

Parameter(s) returned(example parameter name)

Parameter type

Description

Assignment

Yes

AssignedTo

System.String

CC

System.Collections.ArrayList

Comments

System.String

Subject

System.String

Duration

System.Double

DurationUnit

Microsoft.Office.Workflow.Actions.DurationUnit

DueDate

System.DateTime

Boolean

No

Yes/No

System.Boolean

ChooseDocLibItem

No

DocumentLibraryItemName

System.String

Selects list item from a Document Library based on a field value.

ChooseListItem

Changed

ListId

System.String

Selects List Item from list based on a field value.

ListItem

Microsoft.SharePoint.Workflow.SPItemKey

ContentType

Yes

ContentTypeID

System.String

CreateListItem

No

DataSourceDropDown

Yes

DataSourceName

System.String

Drop Down list of DataSources for list associated with workflow.

Date

No

Date

System.DateTime

Date Time Selector

Dependent

Yes

S ystem.String

Based on TextArea DesignerType

DropDown

No

System.String

Email

No

To

System.Collection.ArrayList

CC

System.Collection.ArrayList

Subject

System.String

Body

System.String

Hide

No

Used to hide parameter from users in Designer

FieldNames

No

FieldName

System.String

Select field column from list associated with workflow.

Float

No

System.Float

HyperLink

No

Link

System.String

Integer

No

System.Int32

ListItems

Yes

System.String

ListNames

No

ListTitle

System.String

Drop Down with list of list names from current site

Operator

No

Drop-down list box control that includes operators used to evaluate each side of the RuleDesigner sentence. Operators are static and must be added in Options elements.

ParameterNames

No

System.String

Allows the creation of a new variable for the workflow.

Person

No

Users

System.Collections.ArrayList

Allows selection of multiple users

SinglePerson

Changed

System.Object

Allows selection of a single user

StringBuilder

No

System.String

Survey

No

Creates a task in the workflow to gather data from users.

TaskSummary

Yes

TaskProcessName

System.String

Text

No

System.Object

TextArea

No

System.String

UpdateListItem

No

ListItemToUpdate

WritableFieldNames

No

System.String

Drop down including list of fields on list that are writable

So far, the main changes appear in the return types of the ChooseListItem and SinglePerson DesignerTypes. In SharePoint 2010, the SinglePerson form returns a generic System.Object rather than a string, and the ChooseListItem’s ListItem parameter returns a new type of SPItemKey instead of a string.

To accommodate the return of an Object from the SinglePerson DesignerType form, simple define the parameter as System.Object in the .actions file and the DependencyProperty in code, then define the activities property as a String and explicitly convert it from object to string in the get statement.

The SPItemKey type appears to be a wrapper for returning an instance of the list item. It has two public properties: Id as Int32 and Key as String where the Id is the selected ListItem’s Id and Key is the name. You can programmatically get an instance of the SPListItem by passing the SPList object as a parameter to SPItemKey.GetItemByIdFromList(SPList).

Public Members for Microsoft.SharePoint.Workflow.SPItemKey

Constructors

SPItemKey()

Returns object with Key = string.Empty, Id = -1

SPItemKey(Int32 id)

Returns object with Key = id.ToString(), Id = id

SPItemKey(string key)

Returns object with Key = key, Id =Int32.Parse(key)

Methods

Equals(object rhs)

Boolean

Determines if current object equals object passed in

Equals(object objA, object objB)

Boolean

Determines if two objects are equal

Finalize()

Void

Empty override of base System.Object.Finalize()

FromItem(SPListItem listItem)

SPItemKey

Returns SPItemKey object given SPListItem

GetHashCode()

Int32

Generated from Exclusive OR operation between Id and Key.GetHashCode()

GetItemByIdFromList(SPList)

SPItemKey

Returns SPListItem from given list from Key or Id property

GetType()

Type

Returns Type for current SPItemKey

IsEmpty(SPItemKey)

Boolean

Static. Returns true if both Id and Key properties are null or if Id = -1 and Key is null or string.Empty

MemberwiseClone()

Object

Creates a shallow copy of the current SPItemKey

op_Equality(SPItemKey lhs, object rhs)

Boolean

Static. Determines if SPItemKey and Object are both null or equal

op_Equality(SPItemKey lhs, SPItemKey rhs)

Boolean

Static. Determines if two SPItemKey objects are both null or equal

op_Inequality(SPItemKey lhs, object rhs)

Boolean

Static. Determines if SPItemKey and Object are both not null or not equal

op_Inequality(SPItemKey lhs, SPItemKey rhs)

Boolean

Static. Determines if two SPItemKey objects are both not null or not equal

ReferenceEquals(object objA, object objB)

Boolean

Static. Determines if two objects are references to the same object

ToString()

String

Comma separated string: Key, Id

Properties

Empty

SPItemKey

Static. Returns empty object using empty constructor

Id

Int32

Read/Write. Id of SPItemKey

Key

String

Read/Write. Key of SPItemKey

To access the new type in your class, be sure to reference the new assemblies for SharePoint 14 including C:Program FilesCommon FilesMicrosoft Sharedweb server extensions14ISAPIMicrosoft.SharePoint.dll and C:Program FilesCommon FilesMicrosoft Sharedweb server extensions14ISAPIMicrosoft.SharePoint.WorkflowActions.dll.

Looking at the SharePoint 14 codebase, there are several new activities included in the namespace Microsoft.SharePoint.WorkflowActions.WithKey that use the SPItemKey object includng the same ListItem property as well as additional properties such as TaskId. It appears that the workflow activities in the new version of SharePoint uses this object extensively for List Items, probably as a smaller object to pass around instead of the full SPListItem object. It will be interesting to see how, if at all, this object changes in the beta release.