Share via


Creating Project Workflows using Visual Studio 2012

In Project Server 2010, Project developers were able to create Project Workflows using Visual Studio 2010. In Project Server 2013, we enabled creating the workflows with SharePoint Designer, which makes it much easier and faster to create Project Workflows. In that blog post, we showed how we have simplified the workflow creation for Project using SharePoint Designer 2013.

We are, however, still supporting creating Project Workflows with Visual Studio for the more complex set of workflows, and in fact, have also made it easier to create Project Workflows with Visual Studio 2012. Below, we are going to use a sample two-stage workflow to show how you can create workflows with Visual Studio 2012:

1. Creating the Workflow solution: File Menu>New>Project>Office/SharePoint>SharePoint solutions > SharePoint 2013 Project. Give this project a name, and hit OK:
clip_image002

In the customization wizard, enter the address of the PWA web you’d like this workflow to be published to. Then, pick the sandboxed solution option to limit this workflow to this particular PWA web:
clip_image004

2. At this point, the project you’ll see the empty canvas. In the Project Menu, click on the Add New Item, and from the Office/SharePoint tab, select Workflow, enter a name, and hit Add:
clip_image006

Then, in the customization wizard, pick Site workflow:
clip_image008

Then, pick the history list and the workflow tasks list from that site. We recommend that you use the default lists since a number of PWA UI entry points, use these default lists. Then, hit Finish:
clip_image009

3. Now, we need to set up the environment to use the Project Server activities. In the toolbox, right click and click on “add tab”, and call the new tab “project server”:
clip_image011

Then, right click on the “project server” tab and click on “choose items” from the menu, and you’ll see this dialog:
clip_image013

In the dialog click on Browse, and navigate to where the workflow dlls are located. They are usually located in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\WorkflowActivities
You’ll see two activities dll there. Open the project server one (Microsoft.Office.Project.Server.WorkflowActivities.dll), and hit OK. You are now taken back to the “toolbox items” dialog, and highlights the selected corresponding activities. Hit OK to continue.
clip_image015

4. You might see a “sequence” in the canvas. Delete that, and from the toolbox, pick Flowchart and add it by dragging it into the main area. This flowchart will be the main container of all the stages of the workflow:
image

In the toolbox, click on Control flow, and add the sequence inside that flowchart. Throughout this sample workflow, we will use sequence to represent workflow stages in Visual Studio. This is similar to how SharePoint Designer handles each stage, i.e. each stage is equivalent to a separate sequence in Visual Studio:
clip_image019

Rename the sequence to “Create_Stage” by clicking on the “Sequence” and start typing to change the name. Drag the line from start to “Create_Stage” to connect them together:
clip_image021

 

5. Double click on the “Create_Stage” to drill into this sequence

a. Under project server in toolbox, add the “EnterProjectStage” and “ExitProjectStageGate” activities to the sequence. These two activities are required in any of the PWA stages in Visual Studio.

b. In the properties of “EnterProjectStage”, change the StageID to the Stage ID of the particular stage you’d want this sequence to represent. You can find the stage ID in the URL of that stage, and is available if you navigate to that stage in PWA Settings > Workflow Stages, and then click on the particular stage. Since stageID is a string, the ID should be provided in quotation marks.

c. Put another sequence between “EnterProjectStage” and “ExitProjectStageGate”. Essentially, everything in this sequence is what is represented in the text-based designer in SharePoint Designer stage definition.

d. From project server item in the toolbox, drop the “waitForProjEvent” activity in that sequence:
clip_image022

e. Change the EventName property to “OnProjectSubmit”. The other supported Event Names are “OnProjectCommit” and “OnProjectCheckIn”

6. In the breadcrumb, click on Flowchart to go one level up. Add another sequence after Create_Stage and call it Finished_Stage, and connect the wire from Create_Stage to the Finished_Stage:
clip_image023

7. Similar to the Create_Stage, add the EnterProectStage and ExitProjectStageGate activities to the sequence as well as the WaitForProjectEvent activity in the middle, and set the properties accordingly:
clip_image024

 

 

8. This completes building the workflow in Visual Studio. However, in order to make sure that the workflow can be properly published to the PWA, we need to make a few more changes in the xaml files of the project: From solution explorer, pick “Elements.xaml” under the workflow node

a. Replace the WSEventSourceGUID with the following so that the workflow is correctly identifies as a project workflow:
<Property Name="WSEventSourceGUID" Value="5122D555-E672-4E5D-A7C4-8084E694A257" />

b. Inject the following properties under the “Url = WorkflowStartAssociation”:
      <Property Name="Microsoft.ProjectServer.ActivationProperties.ProjectId" Value="" />
      <Property Name="Microsoft.ProjectServer.ActivationProperties.CurrentStageId" Value="" />
      <Property Name="Microsoft.ProjectServer.ActivationProperties.RequestedStageId" Value="" />
      <Property Name="WSEventContextKeys" Value="Microsoft.ProjectServer.ActivationProperties.CurrentStageId;#Instance&#xA;Microsoft.ProjectServer.ActivationProperties.ProjectId;#Instance&#xA;Microsoft.ProjectServer.ActivationProperties.RequestedStageId;#Instance&#xA;" />

9. Now that everything is set, and the workflow is ready for publishing, click on the “Build Solution” under the Build menu, and then click on the “Deploy Solution” under the Build menu. The wsp file is now deployed to the site. You can also find a copy of the wsp file in the file system, under [project name]>bin>debug

Now, the workflow will show up in PWA. If you navigate to PWA Settings > Enterprise Project Types, and create a new Enterprise Project Type, you will see this workflow as one of the options in the workflow dropdown list.

For more information, see Getting started developing Project Server 2013 workflows in the Project 2013 SDK.

Comments

  • Anonymous
    December 20, 2012
    I could't find where I leave my comment, if you could send me a e-mail with my doubt I'll be appreciated. My e-mail is edgarm@jmalucelli.com.br

  • Anonymous
    December 20, 2012
    Hello Everyone! I have a doubt! I can not find the right dll in the indicated path. I only founded the Microsoft.SharePoint.WorkflowServices.Activities.dll in there. Are there an other place to find it?

  • Anonymous
    April 22, 2013
    The comment has been removed

  • Anonymous
    October 10, 2013
    Is it possible to have one workflow accesing two list? I mean listB needs item from listA. I did it using visual studio but there is an error.. please help

  • Anonymous
    April 27, 2014
    Although i applied the whole step correctly,when i checked in the project dont skip checked in step from workflow.What is the reason for this?

  • Anonymous
    May 14, 2014
    Very important and helpful topic--but there are some issues getting it to work. In step 8,it appears that "Elements.xaml" should be "Elements.xml" Step 8b is truncated. Don't know what the rest should be. Have 8 errors on Building. Please review, test, and update.

  • Anonymous
    October 12, 2014
    Is there a way to read the project owner so that i can send mail to him. I searched all the controls but i found nothing Thanks

  • Anonymous
    March 26, 2015
    SharePoint 2013 has introduced a new workflow platform. The new workflow platform can be leveraged by the new apps for SharePoint as well as classic SharePoint solutions. In this session, we will demonstrate the development experience and lifecycle management of the new workflows in context of a SharePoint App and a SharePoint solution. We will walk through real-world scenarios where some key new workflow features can add value. We will demonstrate how to use those key features. The features include, but are not limited to calling web services from workflow, using custom UI, and influencing behavior of in-flight workflows by sending custom messages to the workflows.