Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / productivity / SharePoint

Leave Approval without Workflow

5.00/5 (1 vote)
4 Sep 2012CPOL5 min read 21.5K  
The Content Approval feature using a Leave Approval scenario.

Introduction

In this article we can explore the Leave Approval scenario without using Workflows.

Scenario

Following are the users of the system.

  1. manager (The Manager)
  2. employee1 (An Employee)
  3. employee2 (Another Employee)

An employee can apply for a leave using the list named Leaves. The Manager has the right to approve or reject a leave application. The employees should not see the applications of other employees. How can we attain the functionality?

Solution

We can have two approaches for a solution here:

  • Use List Content Approval
  • Use Approval Workflow

For simplicity sake, we are using the List Content Approval feature. The Workflow based solution can be used for more complicated scenarios.

Image 1

Following are the steps involved in the List Content Approval solution.

Create New Users

Create three new users for our purpose. If you are using the Windows 7 Operating System, go to Control Panel > Users Accounts item.

Image 2

If you are using the Windows Server Operating System, use the Active Directory section of the Server Manager application to add the new users.

Image 3

Create New Site Collection

After creating the users, create a new Site Collection from Central Administration. Set the Manager as the Primary Site Collection Administrator.

Image 4

Note: Adding as Primary Site Collection Administrator adds the manager user into the Site Owners group in Site Permissions. Owners should have permissions to change the settings for lists, view, etc.

Assign Site Permissions

After creating the site collection open the new site using the URL. Sign in as the user manager.

Image 5

Go to Site Actions > Site Permissions and open the Members group.

Image 6

Add the other two users (employee1, employee2) into this group using the New > Add Users menu item. After adding the two users the list should look like:

Image 7

Now these users should be able to view the lists and libraries inside the site collection.

Create New List

Now perform the following:

  • Open the Site Collection using URL
  • Sign in as the Manager user
  • Create a custom list named Leaves
  • Add the following columns into the List

Image 8

You can see that the Created By, Modified By columns are automatically added and represents our employee who applied for the leave.

Following is the default View of the List.

Image 9

Enable Content Approval

This is the core part of the article and we are going to enable the Content Approval feature of SharePoint 2010. On enabling this feature the List item will have:

  • A new column named Approval Status (Pending, Approved, Rejected)
  • A notification send to Manager when an item is created for Approval
  • A notification send to Employee when an item is Approved or Rejected

To enable this feature, open the above list in manager mode and go to the List Settings.

Image 10

From there choose the Versioning settings link as highlighted above. Choose the first option Require content approval for submitted items, and click the OK button.

Image 11

Now you can see that a new column is added to the List view.

Image 12

Note: The same can be achieved using the Server Object Model list property EnableModeration.

Modify Default View

We need to do a slight modification on the View of the Leaves list. Currently the view shows leave applications of all employees. We need to restrict it to show only:

  • The current logged in user leave applications
  • Or

  • The leave applications which are pending

Note: Views provide flexibilities like applying multiple views and changing an existing leave.

To achieve this, open the Leaves list and go to List tab and click on the Modify View button as shown below:

Image 13

Scroll down to the Filter section and set the following:

Image 14

The filter shows the item only on the following true condition:

  • Created By column equals [Me] as Logged in user
  • Or

  • Approval Status column is equal to Pending

Sign in as Employee 1

Now you need to sign in as user Employee 1. For this, create a new browser instance with a new session.

Note: If you are using Internet Explorer, press and release the Alt key in the keyboard to see the File menu. From the menu click the New session menu item.

Image 15

In the appearing new browser instance, sign in as Employee 1.

Image 16

Now create a new leave item inside the Leaves list. Set the leave time as Reason for Employee 1 as shown below.

Image 17

You can see that the Approval Status is automatically set to Pending.

Sign in as Employee 2

Now you need to sign in as user Employee 2. For this create a new browser instance with a new session. Use the same Alt + File > New Session if you are using Internet Explorer.

In the appearing new browser instance, sign in as Employee 2.

Image 18

Now create a new leave item inside the Leaves list. Set the leave time as Reason for Employee 2 as shown below.

Image 19

You can see that the Approval Status is automatically set to Pending.

Note: You can see that Employee 1 is only able to see his own leave item and the same is the case for Employee 2. The filtering of the View is doing this magic.

Back to Manager

Now you can go back to the manager browsing session. You should be able to see both the list items.

Image 20

As a manager you can Approve or Reject the item by selecting the list item and using the tool bar button.

Image 21

On clicking the Approve/Reject button, you will get the following dialog.

Image 22

You can repeat the same for the second item too.

Back to Employees

Back to the Employee 1 session, you can see the corresponding leave item as Approved.

Image 23

Now back in the Manager screen, reject the remaining leave item and login as Employee 2 to see the status as Rejected.

Image 24

So this concludes our Leave Application implementation without using Workflows. For the flexibility of the Manager you can edit the site main page to include the Leaves list as shown below.

Image 25

References

Summary

In this article we have explored the Content Approval feature using a Leave Approval scenario. Following are the points worth remembering:

  • Content Approval allows item approval without using Workflows
  • Approval Status column is automatically added to list items
  • View provides a convenient way to filter items.

To try with the email notification, you need to configure email settings for SharePoint.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)