Enforcing One List Item Per User Per Day Limit In Sharepoint

The Problem: Allowing Only One Submission Per Day

Enforcing a limit of one list item submitted per user per day can be important to prevent spamming or abuse. Reasons to enforce this include:

  • Preventing users from flooding lists with multiple items, which can impact performance
  • Restricting promotional posts or inappropriate content
  • Making sure all users have fair opportunity for submissions each day
  • Forcing quality submissions over quantity since only one daily post is allowed

Without limits in place, some users may submit excessive items which can negatively impact the usefulness of the list and collaboration. Enforcing daily quotas helps maintain order.

Using SharePoint Built-in Throttling Settings

SharePoint Online and SharePoint Server both contain default throttling settings to limit resource usage. However, on their own these settings may not adequately enforce one list item daily limits.

Examples of built-in throttling settings include:

  • List View Threshold limits number of items returned in views
  • Request Throttling restricts resources used per request
  • Concurrency controls simultaneous requests

These are helpful base protections but often have organization-wide scopes and very high limits by default. They don’t account for nuances like items per user per day.

While you can customize parameters, built-in throttling tends to be broad so is hard to target the specific one submission limit effectively.

Custom Throttling with Event Receivers

For precise control, custom SharePoint throttling can be created using event receiver code that runs when an item is added or updated.

Key aspects include:

  • Use the ItemAdding and ItemUpdating event handlers
  • Check current user permissions and quota status
  • Cancel event for users exceeding daily limit
  • Optionally increment daily total in a separate list per user

Example event receiver code:

  public override void ItemAdding(SPItemEventProperties properties) {
  
    // Get current user ID
    var currentUserId = properties.Web.CurrentUser.ID;  
    
    // Check if user has submitted in past 24 hours 
    var since = DateTime.Now.AddDays(-1);
    var filter = $"AuthorId eq {currentUserId} and DateCreated gt {since}"; 
    
    // Query item count for user in period
    var submittedToday = properties.List.GetItems(new SPQuery { Query = filter }).Count;
    
    // Limit to 1 item per day 
    if (submittedToday >= 1) {
      properties.ErrorMessage = "You exceeded daily limit.";   
      properties.Status = SPEventReceiverStatus.CancelWithError;
    }
  }

That covers the basics but additional checks could enhance accuracy of tracking.

Throttling List Forms with Power Automate

Power Automate flows offer another throttling option by running logic before rendering SharePoint list forms. This can validate daily limits:

  1. User accesses new/edit list form
  2. Trigger flow for pre-processing
  3. Flow checks user create/update count for day
  4. If less than daily limit, render form
  5. Else show throttled message

Example flow definition using filter query in Apply to Each:

  {
    "filterQuery": "AuthorId eq '@{triggerBody()?['ActorId']}' and 
                  DateCreated ge '@{utcNow()-1.00:yyyy-MM-dd}'" 
  }

This approach limits access to the form itself, preventing creation over the quota. However, requires more flow infrastructure.

Enforcing Limits with Microsoft Graph throttling Policies

For organization-level control, the Microsoft Graph API provides throttling policies to restrict user actions like list item creates/updates.

Advantages of Graph throttling policies include:

  • Set globally for all SharePoint lists
  • Custom policy conditions using user scopes and quotas
  • Automatic enforcement without custom code

Sample policy restricting list adds/updates to 1 per user per day:

  {
    "displayName": "Daily list item limit",
    "type": "Microsoft.SharePoint.Throttling",
    "settings": { 
      "listItemOperation": {
        "userRate": 1,
        "ttlInSeconds": 86400,
        "appliesTo": "User"
      }
    }
  }  

The main drawback is complexity of setup in Azure AD and Microsoft Graph.

Troubleshooting and Bypassing Limits

When enforcing tight quotas through custom solutions, keep in mind:

  • Monitor event logs and request traffic for errors
  • Handle service account posts separately from normal limits
  • Consider emergency bypass with supervision approval

Throttling should allow typical usage but remain flexible for exceptional cases. Continually tune as needed.

Summary

Enforcing strict maximums like one list item daily per user requires custom code or configurations above SharePoint default throttling. Options range from event receivers on a single list to organization-wide policies in Microsoft Graph.

Balance usability while preventing list abuse and limit bypasses to emergency cases so consistency is maintained.

Leave a Reply

Your email address will not be published. Required fields are marked *