how to limit record of a list programmatically or configuration.

When the user insert record in the list if this list has exceeded the maximum numbers of record allowed, the form of insert have to show a message with a text as:

"Numbers of records has exceeded the permitted limit"

3 Answers 3


On 2013 CSR and the OnPreRender function is one, and maybe even the best way of skinning this cat.
You will have to read the whole list and then not display the Form but a message.

But you can do without CSR and make SharePoint do half the work for you.

A quick and easy ductape patch from the olden days is to hide the NewForm contents.

  • On the NewForm.aspx page add a ListView WebPart, make it list all your items
    change the WebPart Layouts Properties Zone-Index to 1 to make it display below the NewForm
  • Add another WebPart, use a Content Editor WebPart with the contents:


    SP.SOD.executeFunc('sp.js', null, function(){//execute after pageload
        var items = document.getElementsByClassName('ms-itmhover');//all displayed listitems
        if (items.length > 10) {//maximum number of items
            var form = document.getElementsByClassName('ms-formtable')[0];//new form
            while (form.tagName !== 'DIV') {//go up to the enclosing DIV
                form = form.parentNode;
            form.innerHTML = '<h1>Numbers of records has exceeded the permitted limit: '+items.length+'</h1>';
        } else {//optional: hide the View with all the items
            var itemlist=items[0];//first item
            while (itemlist.tagName !== 'DIV') {//go up to enclosing DIV
                itemlist = itemlist.parentNode;


Tip: place the javascript in a separate file and link the Content Editor Web Part to it.. makes it easier to edit... you still have to include the < script> tag!!

Another alternative is:

Limit only one entry per day per user in sharepoint list


  • Thanks for the solution. I executed the above JSOM code but it is hiding entire listview web part. I but i need to hide only "New Item" from DisplayForm.aspx page. How could i fix this this issue on above solution. Apr 4, 2018 at 6:40
  • [I am no longer in the SP world, yeah!] You have to change the JavaScript (this is not JSOM) to match your requirements.... learn JavaScript DOM operations Apr 4, 2018 at 8:01

You can crate Before Event Handler to achive this. You can add business logic for checking the number of allowed records in the method itemAdding

  • A before ER in SharePoint Online?
    – Evariste
    Jul 28, 2015 at 16:07
  • Could you show me some code? Jul 28, 2015 at 16:19
  • I'm quite sure before ER are not possible in Online environment...
    – Evariste
    Jul 28, 2015 at 16:27
  • suppose that is on-premise Jul 28, 2015 at 17:25
  • It is even possible with SharePoint Online as well. Remote Event Receiver can be used to achieve this. In Remote event receiver you have to write your business logic in 'ProcessEvent():' in this method. Link Jul 29, 2015 at 7:47

You can do this with JavaScript as well. You can add business logic and return false if number of records is exceeded in your Presaveaction.

  • Hello Akhoy. I am trying to implement this. For example i have a column A and Column B. Only if Column A is greater than or equal to Column B, i want to save the item or else display a test message. Can you please brief me the code? I am not so strong in JavaScript? I don't want to do this through validation setting. I want to do this through JavaScript on Newform.aspx. Plesae help.
    – AXA240778
    Mar 29, 2018 at 19:34
  • You need to use PreSaveAction. Check this: social.technet.microsoft.com/wiki/contents/articles/…
    – Akhoy
    Mar 30, 2018 at 7:32

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.