The skip to stage feature is designed to allow administrators the ability to restart a workflow and have it attempt to skip along the workflow until it reaches a particular stage. A common scenario for this functionality is when a project has progressed to a specific point in a workflow, but needs to be pushed back to a previous stage due to any number of reasons, such as, a new stage was inserted that needs to be addressed, certain fields need to be changed that are exposed only in previous stages, etc.
Project Server workflows, like SharePoint workflows, must always be executed linearly. They cannot begin execution at random locations within a workflow. Neither can they “jump” from one point to another point, unless coded to do so within the workflow. The skip to stage functionality cannot circumvent this limitation. As such, the issue with restarting a workflow and attempting to push it to a particular point is that any activities which “stopped” the workflow before will continue to do so again. For Example, activities such as SetProjectStage, OnProjectSubmit, OnProjectCommit, the officeTask, ect, will still cause the workflow to dehydrate and give control back to the user. Although for the SetProjectStage activity we have done some extra work and put logic inside it so that it can be skipped, so long as there are no required fields left in the stage
Therefore, to fully work with the skip to stage functionality you will need to wrap activities within “if statements”. When an administrator restarts a workflow and chooses to skip to a certain stage, we pass into the workflow two properties. The first property indicates that a skip stage command has been sent, and the second property contains the stage Guid that the workflow should stop at. Our SetProjectStage activity reads these two variables and skips if the first variable is set to true, and if the current stage is not the stage that is set in the second property. However, it won’t skip if there are required fields in the stage. So you will need to mimic this behavior around your other activities. You should wrap all of the activities between the SetProjectStage activities (not including the SetProjectStage activity) with an ifElseActivity statement that checks the first Property.
Customizing Workflows in Visual Studio to work with skip to stage
To make any workflow work correctly with the skip to stage functionality an “if statement” should be placed around all of the activities between each of the SetProjectStages. The key example of when this would be necessary is for the office task activities.
Screen shot of example workflow:
In the above example the “ifElseActivity1” is used to bypass the leadApproval sequence activity, which contains all of our approval activities.
As you can see from the above screen shot, it is the “if statement” that we need to figure out how to code. In order to do so, we need to be aware of the two properties that are passed into the workflow during a skip to stage event:
WorkflowContext.SkipToStage : Boolean : If true, a skip to stage functionality has been requested
WorkflowContext.StageUid : Guid : Guid of the stage the workflow should skip to
Steps for creating the workflow:
1. Insert and set the properties of a SetProjectStage activity
· You will need to set the “AlwaysWait” property to True in order for the Skip to Stage scenario to properly work.
· If you do not set the Always wait property to true the workflow may not be able to skip to and stop at previous stages.
2. Insert an IfElseActivity
3. Have the activity check the “projectSequence1.WorkflowContext.SkipToStage” variable.
· If variable is set to false, execute all activities
· Else, bypass
The WorkflowContext.StageUid is not needed for the “If Statement” but is there in case you wish to check what stage the user is trying to skip to.
*The complete above example is found in the attached Visual Studio solution.*
Administration: Initiating the Skip to Stage feature
To attempt to force a project to skip to a particular stage, do the following within Project Server.
1. Log into Project Server as an Administrator
2. Go to Server Setting
3. Click on “Change or Restart Workflows”
4. In the top drop down, select the EPT that the project(s) that you would like to restart and skip to a stage belong to.
5. Select the project(s) which you would like restart and skip to stage from the left panel and add them to the right panel.
6. Check the “Restart current workflow for the selected projects” option
a. Alternatively you can also select the “Associate projects with a new Enterprise Project Type:” option. If you select an Enterprise Project Type that has a workflow associated with it, you can then select which stage in that workflow the project(s) should attempt to skip to.
7. Next select which stage the project(s) should attempt to skip to
a. Skip until the current workflow stage
i. Selecting this option will tell the projects to attempt to skip until they reach the stage that the project(s) are in currently
b. Skip to a particular workflow stage & then selecting a particular stage
i. Selecting this option will tell the projects to attempt to skip until they reach the stage that has been selected
ii. If the selected stage does not exist, the workflow will stop at the very first opportunity.
8. Press OK
9. The project restart jobs will be sent to the queue, and the projects will attempt to restart and skip.
Skip to Stage Example
Expected behavior of the skip to stage can be summed up by the following example.
· A workflow has 3 stages
· All stages are marked as “AlwaysWait”
· Project is on Stage 2
· Stage 1’s required custom fields are filled out
· Stage 2’s required custom fields are not filled out
· Stage 3’s required custom fields are not filled out
Administrator will go and:
o Restart Skip to current stage
§ This will make the workflow restart and stop at stage 2
o Restart Skip to stage 1 (trying to make the workflow stop on a stage where all of the require custom fields are filled out)
§ This will make the workflow stop at stage 1 and wait for submit
o Restart Skip to stage 3 (trying to make it jump over stage 2 even though its required custom fields are not yet filled out)
§ Workflow will stop at stage 2
§ Workflow will not be able to skip stage2 if it has required fields.
§ If you really want to skip it, you need wrap the SetProjectStage as well in an if/else skip condition, which checks the SkipToStage variable and the StageUid variable.
o Restart Skip to stage 5 (trying to make the workflow stop on a stage that does not exist)
§ Workflow will stop at stage 1. This is because of the combination of “Destination stage” doesn’t exist & current stage=”Always wait”.
This feature has been designed and created to address the majority of our customer needs when it comes to being able to skip between stages. In this blog we reviewed there are two steps to use this feature. The first is to correctly develop your workflows to be able to skip over the activities that are between the SetProjectStage activities. This is done by wrapping the activities within an ifElse activity. And the second stage is to restart the workflows and select the stage the project should attempt to skip to. This is done with Project Server –> Server Settings –> Change or Restart Workflows.
If you have any additional questions please feel free to post comments, and I will follow up accordingly.
Popularity: 1% [?]
Other posts like this one: