Click here to Skip to main content
15,798,825 members
Articles / Productivity Apps and Services / Sharepoint / SharePoint 2013

Unique Entries Based on Multiple Columns in Sharepoint List

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
11 Sep 2017CPOL1 min read 18.2K   3
Populate list data from Sharepoint service and then check user input when save button submitted


By default, Sharepoint list only allows unique entries from one column. The traditional way is we query data from database to check the user input, throw a message when condition matches. In Sharepoint, we can populate list data from Sharepoint web service and compare it with user input, when matching data is found, throw an error “Data already exists”.

Using the Code

I have made a list application with name Employees, I have added 3 columns - Name, Email, and Phone with data type text.

Image 1

Maybe you see my application looks different style because I have made custom CSS for my Sharepoint site. Below is new item form.

Image 2

Here it is my step to create unique validation, I will make validation from column Title, Name, and Email. So when user input already exists based on that 3 columns error message appear and data won’t be saved.

  1. Open Sharepoint designer and open your site. In this case, my site is http://bhpsp03srv/.
  2. Open List and Libraries > Employees > NewForm.aspx.

    Image 3

  3. Add jquery reference and our validation script under </Sharepoint:UIVersionedContent> and above </asp:Content>.

    Image 4

  4. This is our script:
    <script type="text/javascript" 
    src="" />
    <script type="text/javascript">
        // adding javascript to button onclick event to call checkExist() function
        var oc = $(' input').attr('onclick');
        $(' input').attr
           ('onclick','if (checkExist())
           {  alert("Employee Already Exist"); }else{'+ oc +'}');
        //variable to hold Ajax result
        var dataResults;
        //Ajax to populate data from Employees list
            url: "http://bhpsp03srv/_api/web/lists/getbytitle('Employees')/items",
            type: "GET",
            async: false,
            headers: { "Accept": "application/json;odata=verbose" },
            success: function(data) {
                dataResults = data.d;
        //function to compare user input and existing data
        function checkExist(){
            var title = $(' > tbody > tr:nth-child(1) > 
                   > span > input').val();    
            var name = $(' > tbody > tr:nth-child(2) > 
                   > span > input').val();    
            var email = $(' > tbody > tr:nth-child(3) > 
                   > span > input').val();    
            var c = null;
            $.each(dataResults, function(i, item){
                $.each(item, function(i, dt){
                    console.log(dt.Title + '  ' + dt.Name + '  ' + dt.Email);
                    if (dt.Title == title && dt.Name == name && dt.Email == email){
                        c = true;
                        return false;
            return c;  
  5. Try to add new item that already exists, gotcha you’ve done:

    Image 5

  6. For edit item, you can do the same thing.

Points of Interest

Why does Sharepoint not make this feature, or maybe I can’t find this feature. Hope it helps you guys!


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

Written By
Indonesia Indonesia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

SuggestionCould not get this to work Pin
Member 1405591013-May-20 11:01
Member 1405591013-May-20 11:01 
QuestionClever Pin
Member 1457120028-Aug-19 5:51
Member 1457120028-Aug-19 5:51 
GeneralMy vote of 4 Pin
Member 1236439013-Sep-17 22:12
Member 1236439013-Sep-17 22:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.