Create A Custom SharePoint Designer Workflow Action

This is an article that was submitted by Gene Vangampelaere for
the European SharePoint Conference.
Gene is a SharePoint architect/ developer in an educational
institute. He works mainly on no-code-solutions.

I always encourage the power users to build their own
applications by using the out-of-the-box tools. The more advanced
applications need the assistant of SharePoint Designer to create
workflows. In some cases the OOTB workflow actions are to
limited.

 

a3

It is possible to create you own SPD workflow actions and let
your (power) users use them. To create a custom action you need
Visual Studio and some coding experience.

Creating the custom action

Create a new “Workflow activity Library” project in VS.

Workflow Action

 

In my example the activity queries a database to get the name of
the course of a student. I named my activity “StudentEmail” (I’ll
use the email of the student as key to get the information).

Add a reference to the Microsoft.SharePoint and
Microsoft.SharePoint.Workflow assemblies.

A custom SPD workflow action can contain some parameters. In my
case I need the emailaddress of the user and the output parameter
will give me the name of the course. Those parameters are visible
in SPD when you select the workflow:

Workflow Action

 

I’ll show you later how you can edit this sentence.

You have to register each property you want to use
in you workflow in this way:

Public Shared EmailProperty As DependencyProperty =
DependencyProperty.Register(“Email”, GetType(String),
GetType(StudentEmail))
<DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)>
_
Public Property Email() As String
Get
Return MyBase.GetValue(StudentEmail.EmailProperty)
End Get
Set(ByVal value As String)
MyBase.SetValue(StudentEmail.EmailProperty, value)
End Set
End Property

The actual code of your workflow you can put in the Execute
method:

Protected Overrides Function Execute(ByVal executionContext As
System.Workflow.ComponentModel.ActivityExecutionContext) As
System.Workflow.ComponentModel.ActivityExecutionStatus
Try

Modern approvals in Office 365 with Power Automate and Microsoft Teams
‘do your stuff here

‘…

Catch ex As Exception : Me.Opleiding = ex.Message
End Try

Return ActivityExecutionStatus.Closed
End Function

To enable this in SPD you need to do a few more things:

Create a .ACTIONS file

The custom actions are described in a .ACTIONS file. You can
find those files in the 12hive folder  on your SharePoint
server:

X:Program FilesCommon FilesMicrosoft Sharedweb server
extensions12TEMPLATE[LANGUAGE CODE]Workflow

The .ACTIONS file contains something like this:

<?xml version=”1.0″ encoding=”utf-8″?>
<WorkflowInfo>
<Actions Sequential=”daarna” Parallel=”en”>
<ActionFONT-FAMILY: ‘Courier New'”>Get the course of a given
student (email)”
ClassName=”Howest.SPDActions.Bamaflex.StudentEmail
Assembly=”Howest.SPDActions.Bamaflex, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=c401f7f296f6b46d”
AppliesTo=”all”
Category=”Howest custom Actions“>
<RuleDesigner Sentence=”Get the course for
studentemail: %1 (save it in %2)
“>
<FieldBind Field=”Email
DesignerType=”TextArea” Text=”email”/>
<FieldBind Field=”Course” DesignerType=”ParameterNames”
Text=”CourseName”/>
</RuleDesigner>
<Parameters>
<Parameter Direction=”In” />
<Parameter Direction=”Out” />
</Parameters>
</Action>
</Actions>
</WorkflowInfo>

The action name attribute describes the sentence you see in the
actions selection window. The RuleDesigner Sentence attribute is
the sentence you see when you select your action. The parameters
are set as %1 and %2
(and so on). More information about the .Actions file you can
find here.

Be sure you sign your assembly and add the PublicKeyToken and
the assemblyname in this file. When the action is not shown in
SharePoint Designer it is often the case that the assembly
signature is incorrect.

Modify web.config

The next step is to modify the web.config (on each front end
server). You have to add a new AuthorizedType.

<authorizedType Assembly=”Howest.SPDActions.Bamaflex,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=c401f7f296f6b46d

Namespace=”Howest.SPDActions.Bamaflex” TypeName=”StudentEmail”
Authorized=”True” />

Again, be sure you add the right assembly signature. And do not
forget to add the assembly in the GAC (c:windowsassembly) on you
SharePoint servers.

At the end you should get a custom workflow action!

Share this on...

Rate this Post:

Share: