Creating a Vacation Request Workflow in SharePoint Designer
I am new to SharePoint and even newer to SharePoint Designer (SPD). I was asked to “look into” creating a workflow in SharePoint that would automate the approval of vacation requests. What the heck is a workflow, I asked myself. Being who I am, I can hardly ever “look into” anything without being challenged to successfully complete the task. So I briefly researched many sources of information regarding the creation and purposes of workflows. After having a basic understanding, I jumped in feet first trying to begin the workflow using an Out of the Box (OOTB) template in SharePoint 2007. I soon discovered that the OOTB solution would not do everything I needed it to do. Now I need to learn SharePoint Designer.
Because it took me a while to learn how to do everything I needed to do, I decided to post instructions on how I created the workflow for my future use and for anyone else that may find it useful.
Here’s what I needed the workflow to do:
Assign the specified supervisor a task to review and approve or reject the request.
If approved, send an email to HR with the details of the request
Send the person that submitted the request a confirmation message
Add the name and dates to a departmental vacation calendar
If rejected, send the requestor a message with supervisor comments
However, because of some limitations in SPD, I ran into a few snags, but I did find workarounds. The first snag was that I wanted the workflow to send an email with the requestor’s name and details of the vacation to HR upon approval. When I added lookup to body of the message in SPD I told it to pull that information from the Name column of the list. Because the column was a “People or Groups” column, it returned the name like this “DOMAIN\username”. The easiest thing to do was to change that column name to username, so SharePoint would be able to get info from Active Directory. I then created another column called Full Name and had the users put their name in, so this is what I included when I added lookup to body in SPD. I’ll cover this in more detail later.
Here’s what I did to make it work:
Create a custom list on SharePoint called Vacation Request with the following columns:
Username – Person or Groups
Full Name – Single line of text
Department – Choice (menu to choose from)
Supervisor – Person or Groups
Type of leave – Choice (menu to choose from)
Begin Date – Date and Time
End Date – Date and Time
Employee Comments – Multiple lines of text
Now that the list is created in SharePoint, we need to launch SPD and open the site. Once the site is opened we need to create a new workflow by clicking File > New> Workflow.
In the following steps we will be assigning names to the workflow, tasks, variables, etc. You can use whatever names that fit your needs.
Defining the workflow
Name the workflow “Vacation Request” and choose “Vacation Request” in the dropdown list because it is the list that was created, and the workflow needs to be attached to it.
Check the box that states “Start automatically when a new item is created” and click next.
Setting Actions for the workflow’s first step
Give the step a name. This is the name of the task that is to be assigned to the supervisor.
When an employee submits a vacation request, a task needs to be assigned to their supervisor so the request can be approved or rejected.
By providing certain information in the next step, SPD will create a form that will allow the supervisor to Approve or Reject the request and include comments.
Click Actions and choose Collect Data from a User
Now there three things we need to provide to SPD:
1. The Data that needs to be collected
2. The User that needs to provide the data, the department supervisor in this case
3. A Variable to collect
Click on the data link and a wizard will start. Assign a name for the task when prompted.
There are two things that need to be collected from the supervisor:
- Is the request approved or rejected?
- Additional comments
Click on the Add button to add the Approve/Rejected and Comments
The first question is the status, Approve or Reject. We will use a choice field here.
Click finish and add another field so the supervisor can include additional comments
Once you have added these two fields, click Finish to complete the data portion of the acton.
In this step, we need to identify who the supervisor is. In my situation, we have several departments with a different supervisor for each one. In order to keep things simple, the employee that fills out the request has to provide the supervisor’s name. Remember the custom list with the Supervisor column? We are going to tell the workflow to collect data from whatever name is in that field.
Click the “this user” link, select “Workflow Lookup”, click Add>>
The source should be current item and the field is “Supervisor”. We are telling SPD to collect data from whatever name is in the Supervisor field in the custom list we created.
Variable to collect:
Now we’ve created a task for the supervisor to approve or reject the vacation request.
Because we need to use the outcome of the task, we need to save the ID of the task that we’ve created. This is the variable that we want to collect.
We are going to store the ID of the task in a new variable called VacationRequestTaskID
Click on the Variable link and select Create a new variable.
Name the variable VacationRequestTaskID and choose List Item ID as the type
Now the first action of “Collect data from a user” is complete. What we need to do now is save the information collected from the supervisor: was the request approved or rejected, and what are the comments.
To save this information, we need to create two variables to store it; one variable to store Approve or Rejected, and one variable to store Comments.
Add another Action “Set Workflow Variable”. If it’s not in the list, click on “More Actions”
Type in VacationApproved for the name and select String for the type. Click OK
We have created the variable, now we need to tell it what to keep. Click the “Fx” button.
We need to collect the information that the supervisor provided in the task that we created earlier. Since we saved the ID of the Task in a previous step, we know that we are looking for the VacationRequestTaskID
Choose Tasks from the Source dropdown box. The information we need for this is if the request was Approved or Rejected. Remember the field we created earlier with the Radio Buttons Approve and Reject? We named it Vacation Request Approve Status, so select that for the Field.
Match up everything like in the illustration below and perform the same steps for the comments.
Once completed, the actions should look like this
Notify HR and Requestor of Approval Status
We need to notify HR and the requestor of the approval status. If the request is approved, then send an email to HR and to the requestor with the details of the request.
If the request is rejected, then send the requestor an email with the supervisor’s comments.
Click the link to Add a Workflow Step and give it a name. For this step, we need to add Conditions and Actions.
Click Conditions and choose ‘Compare any data source’
We need this option to look to the variable that tells if the request was approved or rejected.
Click on the value link and type in Approve
Now click “Actions” and choose “Send an Email”
For my situation, I needed to send an email to the requestor and to HR. Now it’s time to define the email message. Click on the book at the end of the To: field. Select Workflow Lookup, choose Current Item for the Source and Username for the Field. You can then add the email address of HR to Selected Users.
I want the email that is sent to the requestor and HR to include details about the vacation request such as leave type, dates, department, etc. To do this we need to click the “Add Lookup to Body” button. From there you can find all the information you need from “Current Item”.
Notice that I typed in headings before each lookup such as Name, Department, etc. and I used HTML tags to further customize the look of the message.
The resulting email will look like this if you use the same format as I did.
Okay…so, we have set this up to send an approval email if the request is approved. Now we need have the workflow send a message to only the requestor if it is rejected. To do this, click “Add else if Conditional Branch” and do the same thing as we did for the approval, but instead of the condition being” Else if Variable:VacationApproved equals Approve”, we need it to be “Else if Variable:VacationApproved equals Reject”. The action will still be “Send an Email”.
Adding vacations to departmental calendars
The last step we need this workflow to do is to add the approved vacations to the appropriate vacation calendars. First, we need to create a calendar list for each department.
Essentially, we need to add another step and add conditions and actions that have the workflow add a list item to the department calendar if the request is approved.
This is where I ran into another problem. In my situation, each department has their own site within the same corporate site collection. Our Vacation Request list that we created in the first step resides on the main page of the site collection so everyone can access it. I wanted each departmental vacation calendar to reside on their department’s site so only that department could have access to it. SPD can’t add a list item with information from the vacation request list to the vacation calendar if it is on a different site. Here is the workaround. Create all departmental vacation calendars on the main page giving them distinctive names such as, Financial Services Vacation calendar, Accounting Vacation Calendar, etc., but click the “No” radio button where it asks “Display this list on the Quick Launch”. Then go to each department’s site and create a link to their vacation calendar on the main page. This way the vacation calendars will not be visible from the main page.
Once all vacation calendars are created, add another step to the workflow. Create the following conditions and actions for the first department.
Action: (Compare any data source) ” Else if Variable: VacationApproved equals Approve”
Condition: (Create List Item) “Create item in Accounting Vacation Calendar (Output to Variable: create )
Click on the “this list” link and choose the department vacation calendar. You will then have three fields to configure. Title (*), Start Time (*) and End Time (*).
Highlight the Title (*) and click modify.
The Value Assignment box will pop up.
You can leave the “Set this field:” to Title.
Click the Fx button for “To this value:” and coufigure as follows:
Source: Current Item
Field: Full Name
Do the same for Start Time(*) and End Time (*) and choose the begin date and end date from the current item. For each separate department, click Add ‘Else If’ Conditional Branch and repeat the above steps. Finish the workflow and test.
Once the workflow has been created, be sure to manage permissions for all of the vacation calendars that were created and the vacation request list.