Share via


SharePoint 2013: Multi-level Approval workflow that with custom code activity using Visual Studio 2013

Learn how to use a sequential-style workflow to route a workflow to multiple level depending on the course the workflow takes.

Download Source Code

Summary

Demonstrates how to use a sequential-style workflow to route a workflow to multiple levels depending on the approval status.  It also creates a subsite using a custom activity after approval by all level.

This basic workflow scenario supports a review and approval/reject process. The workflow starts when a list item is submitted. The workflow assigns a task to first level user group, who review the request, makes comments as necessary, and then concludes the task by either approving or rejecting the request. The workflow ends when the request is rejected. Additional tasks are assigned to the second level user group after approval from first level. On rejection, the workflow ends and on approval, a new subsite is created using the custom code activity added in the workflow.

Prerequisites

This sample requires the following:

  • SharePoint 2013 installation that is connected to a configured Workflow Manager 1.0 farm.

  • Workflow Manager 1.0 that has the March 2013 cumulative update applied.

  • Service Bus 1.0, with the Mach 2013 cumulative update applied.

  • Visual Studio 2013 and Office Developer Tools for Visual Studio 2013

  • Start following services

    • Service Bus Gateway

    • Service Bus Message Broker

    • Workflow Service Backend

Key components of the sample

  • CPApprovalWorkflow.sln contains the entire workflow.

  • CodeActivityLibrary.csproj contains the solution to add custom workflow activity that is used by the workflow

  • The feature folder contains the feature that adds workflow to the list.

     

Configure and build the sample

 

Follow these steps to configure the sample.

  1. Make sure that you have a site collection created using the Developer Site template.

  2. Create two SharePoint user groups named Legal Dept Members and Managers

  3. Open the solution Visual Studio 2013.

  4. Change the Site URL property on the project to be the URL of the developer site.

  5. Build CodeActivityLibrary.csproj and copy the CodeActivityLibrary.dll and AllowedTypes.xml to following locations

    1. C:\Program Files\Workflow Manager\1.0\Workflow\Artifacts

    2. C:\Program Files\Workflow Manager\1.0\Workflow\WFWebRoot\bin

    3. GAC

  6. Build ApprovalWorkflowApp.sln.

     

Run and test the sample

 

  1. Open CPApprovalWorkflow.sln, set the library/list GUID in the Elements.xml file for the list to which the workflow need to be added along with Workflow History List ID and Task List ID.

  2. https://lh3.googleusercontent.com/xV-zFQsgtZct9wdUOyZC90Gg02GHfGLOXtbursq4zq1_H4h8bXtAXCTlnwljFKdmrSb-LDkzOUlDcQxrjamBfcwmZhYvcSr7pSkp6rAaIQefV_bprr5ek2kMkIccyNO-SZx8tVKI

  3. Build and deploy the solution to a developer site.

  4. When the solution is deployed, open the site and list to which the workflow is added to.

  5. Make entry in the list and submit.

  6. Navigate to the Task list and edit the newly created item to approve the request. (1st level)

  7. Check the Workflow log list to view the status of workflow

  8. Navigate again to the Task list and edit the item to approve (2nd level)

  9. Navigate to the Site Contents page to verify if the subsite is created successfully after approval of workflow

  10. If there is any change in the CodeActivityLibrary.csproj project, make the changes, move the CodeActivityLibrary.dll and AllowedTypes.xml to following locations, reopen the Visual Studio and add the activity again in the workflow.

    1. C:\Program Files\Workflow Manager\1.0\Workflow\Artifacts

    2. C:\Program Files\Workflow Manager\1.0\Workflow\WFWebRoot\bin

    3. GAC

  11. It’s recommended to change the Assembly version each time when there is a change in code activity library to make sure that the latest change is updated.

    https://lh3.googleusercontent.com/hGAlQw2J6pVV0JfM8P7zrwNSEfutF8-Q5NtrgDWB21Nl46QdJ1jpM-a0e2qVvukIE5ruoLzoaWnd5vIPofaYZIIHYtFrW3Er9eQ6xqffxY-MTTzYk9vY_qm6tdxmi5pEdPtH-xBt

    https://lh6.googleusercontent.com/SPpg3StwiuSdrzdlaok0eQVab2b8o0IsQvF1uqF15zZioXFy4ky7lvBX9_0s5OPsCmlxTzWrpyma-2np0Opsxn9_tHIIkMWDXnkGbbGOW2hUmBCHuYHhQlMKTip2Aa4L9Mh130us

     

Troubleshooting

If the workflow fails, it is likely due to following reasons:

1. Prerequisites are not installed properly

2. GUID is not correct

3. User groups are not created

Go to workflow page to check the error message.

 

Screen shots

New Site Request List (where the Workflow is added to)

https://lh3.googleusercontent.com/6SQ8Z9yQLO2vnCj1PrQi-AbXqTAJ20e2nHDZxb1v_Uk3v4WEKhenIoA30y6mB7Vd9Yw5OEsTwWT5MLUvL39EUjZwUU-0WNQ94l39D563lsRtogYVjHHdr4Oqc2gYQHigkXyJrJLp

Workflow page of New Site Request list. Workflow started after the list form is submitted.

https://lh3.googleusercontent.com/WvaSS0KFJJy834xl7G0hRlNnww9C08S-1NmPSbvWQ44msFdrAETWvImZOUBkY4K-5gh9bXwu7uWDdwmYOATo31mTo6TVIXETj1LVdFI_W6EziKhvsWPNRAtuY4n4vtZYilTyDZE2

New task has been created and task is assigned to Legal Dept Members group

https://lh4.googleusercontent.com/pN55vknskMu5IOyqnUNJap8e1ZZmOHskObhzhD1F3EELE9zHkBfJeYZkQp40apr2hpfxUUwdW0CY_hnJhiZoCEgIkTqHPYVM64ODklik0K3IZUpgQVwCNrQvqzqsrPuWsidAyyRP

Edit the task and approve/reject the request.

https://lh4.googleusercontent.com/MPfyJvzNDUXSFndL6LQ2iDNuWvWkkXK2IcWyBOMrZhCZMkeZjYMgWkcdPwVTd4yLp_opQj0muZWzVaEq3uot4L3MlMbqMnJ6qjfhwV1izwZl0e05DRqyfOA4PBdT25-wyrJy4bNF

Workflow History with status logged in.

https://lh4.googleusercontent.com/tMjGlirpwLldv4hgDTXq5An7pSwZOwS3qIkBcqOZzVsLrvN8c1toXh9h4_HRUFFLubOTTZ-X5gUhdRjyhIdwpcXt7gNBEkvF6dKq7z1tmWi_G_lFBTeiTjfI8Nwo3f11QQsCi33x

New Tasks has been created and assigned to Managers group

https://lh4.googleusercontent.com/2zDggRl8Xh2pxND90JVxeILbR7zRBbA6Bh_4dHbHBJtMxlVigZvvGQ8yNx7Dj99kE1mDH-v6rvnIT-B9rsYqOBLCFST2etcsLkYCa1XuO9-e5hh4WK28wAMpNQVi_FHnqP94V-NM

Edit and approve/reject the request (2nd level)

https://lh5.googleusercontent.com/KWa8vxS7NhZJhqBrln3GxDIA6CROZgQ8fEICf7N3gXrqpQ1kYyqiUFMDSevwZU_XWWk37zU2wVIhJ5hVfy2ULZ46i6HTYr2F7TxUKjVTN-Efl86Gg2Hs5koJSm2Jcu-BPqxYAdOe

Workflow History with status logged in.

https://lh3.googleusercontent.com/ak3omDcrPqSBj20YBK385cVQWgXNp1By7aXJY57PcM-zb0xK24Drin_aoxIb78UeDXpFgovxscaHDqOsviPwCUmPo5V6lyzY_NEV9NKOGMZnNPUakpYYqpSRM4-975DxSscqKD2P

Subsite created after 2 level of approvals

https://lh6.googleusercontent.com/1tTXhteegzkuqM3GXNZdebmQwuuOPw3xFNonO1Lx80aQEOwj0HDYzwPLspl4XxDD-OWdCl8eUKnpZvQgGnZVBxBnfs-TXtdvtQ5i--m2eivSlQWFUEKOETHkG-UZgsV7r1Sjag44

  Download Source Code