0

I have imported an Excel spreadsheet into a SharePoint list in 2013. There are about 20 columns. I am trying to make the main column, single line text field, (not sure if that is the correct terminology) to enforce unique values. I click to index and I get an error stating that there are duplicate entries but I have visually verified using conditional formatting and there is no duplicate entries. What am I missing?

Thank you in advance with any help.

  • What do you mean, I mean I am not getting which type of column you are making as a single line of text? what is its data type? – Niranjan Kulkarni Jul 14 '15 at 6:32
  • The column contains application names, example: Adobe Acrobat X or Office 2010 or SQL 2008, etc. I want to make this application name field unique so users can't add the same applications. I have verified that the field does not have duplicates but when I enforce unique I get an error stating that are duplicate entries. – Zygon Jul 14 '15 at 11:54
  • You can add some code on sharepoint NewForm using SP2013 designer – Niranjan Kulkarni Jul 14 '15 at 12:05
  • And can achieve that you want – Niranjan Kulkarni Jul 14 '15 at 12:05
0
<script type="text/javascript">

    var titleItem;
    var flg=0;


 function PreSaveAction()
 {

    titleItem = $("input[title='Title']").val();    

    //alert(" "+titleItem);     

    $.ajax({

           url: "http://sp13dev:4149/Appraisals/_api/web/lists/GetByTitle('ListName')/items?$select=Id,Title&$filter=Title eq '"+titleItem+"'" ,

            type: "GET",
            async: false,
            headers: { "Accept": "application/json; odata=verbose",  
                        "content-type": "application/json;odata=verbose", 
                        "X-RequestDigest": $("#__REQUESTDIGEST").val() },
            success: function (data) {

             // alert("WELCOME " + data.d.results.length);

                if(data.d.results.length>=1)
                {
                    flg=1;
                    $("#labelTitle").html("This value already exists in the list.");
                    //  alert("FLAG: "+flg);
                }
                else
                {
                    flg=0;     
                    $("#labelTitle").html("");  

                //  alert("FLAG: "+flg);
                }

            },
           error: function (error) {

                alert(JSON.stringify(error));
            }

        }); 


        if(flg==1)
        {

            return false;
        }       

    return true;

 }


</script>
  • PreSave Action is the inbuilt function of sharepoint in which we can write our CSOM code and can validate duplicate entries before adding them on to the list. Hence forth you have to add the labels naming "labelTitle" below your sharepoiint "Title" field, where you have to restric the duplicate entries. – Niranjan Kulkarni Jul 14 '15 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.