Blog Post

Microsoft SharePoint Blog
2 MIN READ

HOW TO: Develop a workflow code activity in SharePoint 2013

SPDev_Support's avatar
SPDev_Support
Icon for Microsoft rankMicrosoft
May 01, 2019

First published on TECHNET on Aug 28, 2013

This post is a contribution from Raghavendra B Nanjaiah, an engineer with the SharePoint Developer Support team.

First part is to create our code activity and let the Workflow Manager and SharePoint 2013 know about it.

1. In VS 2012, click New Project, Workflow and choose Activity Library.

2. Delete the declarative Activity1.xaml from the solution since we will be creating our own custom code activity.

3. In solution explorer on newly created activity library right click and select add new item -> Workflow -> Code Activity.

4. Decide what data you would like to pass in to custom activity. In my case I am accepting string as InArgument and trying to create new list item based on the input string parameter  (you can also use OutArgument which represents the flow of data out of an activity).

5. Write your activity logic in overridden execute method.

6. Build the Project and sign the code activity assembly.

7. Now, Create a new xml file and name it as AllowedTypes.xml and add the reference of you activity library dll , Namespace and type as shown below ( this basically adds your assembly to whitelist which Workflow service trust and loads. If your assembly is not in whitelist you might receive activity not found exception )

8. Now it's time to deploy our assembly and allowedtypes.xml to the folder from where Workflow manager and SharePoint can read.

* On the Workflow Manager box you have to:

- Copy activity assembly to following locations:

> %ProgramFiles%\Workflow Manager\1.0\Workflow\Artifacts

> %ProgramFiles%\Workflow Manager\1.0\Workflow\WFWebRoot\bin

- Add your activity class to the white-list

> Copy AllowedTypes.xml also to above two locations

- Restart “Workflow Manager backend” service

* On SharePoint box you have to:

- Copy activity assembly to SharePoint box and install it in the GAC.

- Reset IIS

 

Now, the second part is to create a workflow using custom code activity that we created by following the above steps.

1. Now in the same visual studio solution where you have custom code activity add new SharePoint 2013 Workflow project.

2. From the toolbox drag and drop the custom code activity that we just developed.

3. Right click and deploy the solution to your SharePoint site.

 

Bingo! Now we have developed and deployed custom code activity Workflow in SharePoint 2013 with Workflow Manager 1.0.

Hope this helps!

Updated Sep 02, 2020
Version 3.0
  • Yan Kong's avatar
    Yan Kong
    Copper Contributor

    Nice article!  One question.  If only activity.cs is changed, is it enough to just redeploy .dll, not the WSP?