In my previous post, I gave an overview of how to mimic State Machine behavior using sequential workflows developed in SharePoint Designer (SPD) 2007. This post is actually a walk-thru of the development process in SPD 2007.
Create the following 2 lists (See description in previous post cited above):
- Core.NET Content (Document Library)
- Core.NET Approval Workflows (Custom List with following columns)
- Title: Single line of text
- File URL: Hyperlink or Picture
- Workflow Status: Choice (with following choice values)
- Content Analyst: User
- Awaiting Approval
- Pending Analysis & Review
- Awaiting Approval
Create 'Approval Initiation Workflow' on the 'Core.NET Content' list
Open an instance of SharePoint Designer 2007 on your machine. Go to File > Open Site... and enter the URL for the site you created the lists on.
Go to File > New... > Workflow..., enter Approval Initiation Workflow as the name of the workflow, and select Core.NET Content from the drop down list. Make sure that only the second checkbox (Automatically start this workflow when a new item is created) is checked, and click Next
Create workflow action to insert an item into the second list
Enter Initiate Approval process for uploaded content as the Step Name. Click the Actions dropdown button and select Create List Item
from the dropdown. Click the this list link on the action, select the Core.NET Approval Workflows list from the drop down at the top of the 'Create New List Item' dialog, and specify the values for each of the columns as shown below:
- Title = Core.NET Content:Name
- File URL = Core.NET Content:URL Path
- Workflow Status = Awaiting Assignment
Click the Finish button to publish the workflow.
The above step simply takes values from the document library (Core.NET Content) and inserts into the Core.NET Approval Workflows list. We now turn our focus to the other list, and the second workflow.
Create 'Approval Process Workflow' on the 'Core.NET Approval Workflows' list
Create the workflow as below; enter Approval Process Workflow as the name of the workflow, and select 'Core.NET Approval Workflows' list from the drop-down. Make usre that the last 2 checkboxes (Automatically start this workflow when a new item is created + Automatically start this workflow whenever an item is changed) are checked.
Create Variables for the workflow
Click the Variables... button in the Workflow Designer window, and create variables as below:
The 'Approval Process Workflow' will consist of the following 3 steps:
- Get Workflow Data
- Process Workflow Status
- Process Approval/Rejection by Manager
- Update Workflow Status
Note: By updating the list in the very last step, the subsequent instance of the workflow (started on item update) can kick off immediately. If the current workflow updates the list while it still has some more activities to perform, the second workflow fails.
An explanation of each of the step follows:
Step 0: Terminate Workflow if already approved
This step is optional, hence I did not include it in the above list of steps. It simply checks to see if the item has already been approved, and if it is, terminates the workflow using the Stop Workflow activity.
Step 1: Get Workflow Data
This step simply intializes the values of the variables and comprises the following 2 steps:
- Set the ContentAnalyst variable to the value of the Content Analyst column in the Current item. (This value will be empty when the first instance executes)
- Initialize the UpdateStatus variable to 'No'.
Step 2: Process Workflow Status
This step relies on IF condition activities to process the workflow according to the Workflow Status for that particular instance of the workflow.
Refer to the diagram above; starting from the top
- The first time the workflow executes, the status is set to Awaiting Assignment, causing ONLY the Actions for the first Condition to execute. The action themselves are pretty straight-forward and self-explanatory.
- The second condition (where status equals 'Pending Analysis & Review') may be true a number of times, depending on the number of times the manager rejects the document.
Just like the second condition, this may be true multiple times depending on the number of times the workflow was submitted to the manager for approval.
- Alternatively, you can also add a condition here to check if the workflow status is set if 'Approved', and terminate the workflow (as shown below).
Note: You can get the user input for a 'Collect Data from a User' action by simply referencing the column of the Tasks list named after that specific input you specified in the 'Custom Task Wizard' dialog.
Step 3: Process Approval/Rejection by Manager
This step was included since its not possible to have a nested IF statement in the Actions sections of a step.
Either one of the conditions can only be true if and only if the workflow status is Awaiting Approval. If the Manager APPROVED the document, the NewStatus variable is set to Approved, if the Manager REJECTED the content document, the NewStatus variable is set to Pending Analysis & Review, sending the workflow back to the Analyst specified by the Repository Manager.
Step 4: Update Workflow Status
This step MUST execute at the very end, to allow the successful termination of the current workflow instance and initiation of the subsequent workflow instance. Also, the UpdateStatus variable was explicitly set to 'No' at the very start of the workflow instance, and unless a step hasn't set it to 'Yes', the update action in this step will not execute.
This step updates the 'Workflow Status' column
to the value in the NewStatus variable, and the 'Content Analyst' column to the value in the ContentAnalyst variable (shown below).