HOW TO: Develop a workflow code activity in SharePoint 2013

Published May 01 2019 03:49 PM 593 Views
Microsoft

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!

1 Comment
Occasional Visitor

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

%3CLINGO-SUB%20id%3D%22lingo-sub-509847%22%20slang%3D%22en-US%22%3EHOW%20TO%3A%20Develop%20a%20workflow%20code%20activity%20in%20SharePoint%202013%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-509847%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3E%20First%20published%20on%20TECHNET%20on%20Aug%2028%2C%202013%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThis%20post%20is%20a%20contribution%20from%20Raghavendra%20B%20Nanjaiah%2C%20an%20engineer%20with%20the%20SharePoint%20Developer%20Support%20team.%3C%2FP%3E%0A%3CP%3EFirst%20part%20is%20to%20create%20our%20code%20activity%20and%20let%20the%20Workflow%20Manager%20and%20SharePoint%202013%20know%20about%20it.%3C%2FP%3E%0A%3CP%3E1.%20In%20VS%202012%2C%20click%20New%20Project%2C%20Workflow%20and%20choose%20Activity%20Library.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20619px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111503iE72D37B446071D36%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E2.%20Delete%20the%20declarative%20Activity1.xaml%20from%20the%20solution%20since%20we%20will%20be%20creating%20our%20own%20custom%20code%20activity.%3C%2FP%3E%0A%3CP%3E3.%20In%20solution%20explorer%20on%20newly%20created%20activity%20library%20right%20click%20and%20select%20add%20new%20item%20-%26gt%3B%20Workflow%20-%26gt%3B%20Code%20Activity.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20626px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111504i12EF093673D0D3B6%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E4.%20Decide%20what%20data%20you%20would%20like%20to%20pass%20in%20to%20custom%20activity.%20In%20my%20case%20I%20am%20accepting%20string%20as%20InArgument%20and%20trying%20to%20create%20new%20list%20item%20based%20on%20the%20input%20string%20parameter%26nbsp%3B%20(you%20can%20also%20use%20OutArgument%20which%20represents%20the%20flow%20of%20data%20out%20of%20an%20activity).%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20630px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111505i106B4B67E39BBA43%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E5.%20Write%20your%20activity%20logic%20in%20overridden%20execute%20method.%3C%2FP%3E%0A%3CP%3E6.%20Build%20the%20Project%20and%20sign%20the%20code%20activity%20assembly.%3C%2FP%3E%0A%3CP%3E7.%20Now%2C%20Create%20a%20new%20xml%20file%20and%20name%20it%20as%20AllowedTypes.xml%20and%20add%20the%20reference%20of%20you%20activity%20library%20dll%20%2C%20Namespace%20and%20type%20as%20shown%20below%20(%20%3CSTRONG%3E%20this%20basically%20adds%20your%20assembly%20to%20whitelist%20which%20Workflow%20service%20trust%20and%20loads.%20If%20your%20assembly%20is%20not%20in%20whitelist%20you%20might%20receive%20activity%20not%20found%20exception%20%3C%2FSTRONG%3E%20)%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20380px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111506i1BBE12EBBE7F8A0D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E8.%20Now%20it's%20time%20to%20deploy%20our%20assembly%20and%20allowedtypes.xml%20to%20the%20folder%20from%20where%20Workflow%20manager%20and%20SharePoint%20can%20read.%3C%2FP%3E%0A%3CP%3E*%20On%20the%20Workflow%20Manager%20box%20you%20have%20to%3A%3C%2FP%3E%0A%3CP%3E-%20Copy%20activity%20assembly%20to%20following%20locations%3A%3C%2FP%3E%0A%3CP%3E%26gt%3B%20%25ProgramFiles%25%5CWorkflow%20Manager%5C1.0%5CWorkflow%5CArtifacts%3C%2FP%3E%0A%3CP%3E%26gt%3B%20%25ProgramFiles%25%5CWorkflow%20Manager%5C1.0%5CWorkflow%5CWFWebRoot%5Cbin%3C%2FP%3E%0A%3CP%3E-%20Add%20your%20activity%20class%20to%20the%20white-list%3C%2FP%3E%0A%3CP%3E%26gt%3B%20Copy%20%3CSTRONG%3E%20AllowedTypes.xml%20%3C%2FSTRONG%3E%20also%20to%20above%20two%20locations%3C%2FP%3E%0A%3CP%3E-%20Restart%20%E2%80%9CWorkflow%20Manager%20backend%E2%80%9D%20service%3C%2FP%3E%0A%3CP%3E*%20On%20SharePoint%20box%20you%20have%20to%3A%3C%2FP%3E%0A%3CP%3E-%20Copy%20activity%20assembly%20to%20SharePoint%20box%20and%20install%20it%20in%20the%20GAC.%3C%2FP%3E%0A%3CP%3E-%20Reset%20IIS%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%2C%20the%20second%20part%20is%20to%20create%20a%20workflow%20using%20custom%20code%20activity%20that%20we%20created%20by%20following%20the%20above%20steps.%3C%2FP%3E%0A%3CP%3E1.%20Now%20in%20the%20same%20visual%20studio%20solution%20where%20you%20have%20custom%20code%20activity%20add%20new%20SharePoint%202013%20Workflow%20project.%3C%2FP%3E%0A%3CP%3E2.%20From%20the%20toolbox%20drag%20and%20drop%20the%20custom%20code%20activity%20that%20we%20just%20developed.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20301px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111507iEC05B3641040213F%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E3.%20Right%20click%20and%20deploy%20the%20solution%20to%20your%20SharePoint%20site.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBingo!%20Now%20we%20have%20developed%20and%20deployed%20custom%20code%20activity%20Workflow%20in%20SharePoint%202013%20with%20Workflow%20Manager%201.0.%20%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%2019px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111508iC4BF312C2FB88975%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EHope%20this%20helps!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-509847%22%20slang%3D%22en-US%22%3E%3CP%3EFirst%20published%20on%20TECHNET%20on%20Aug%2028%2C%202013%20This%20post%20is%20a%20contribution%20from%20Raghavendra%20B%20Nanjaiah%2C%20an%20engineer%20with%20the%20SharePoint%20Developer%20Support%20team.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-509847%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%20Support%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Sep 02 2020 04:15 PM
Updated by: