0
votes

We have SharePoint Online site with list. Users can add, edit and delete own items in this list. How I can resolve new issue - Users can't edit and delete own items older than one week (from creation date). Is it possible without coding Remote Event Reciever or Azure function?

3
" Users can't edit and delete own items older than one week (from creation date)", are you facing this issue? or you want to implement this? - Muhammad Murad Haider

3 Answers

1
votes

Per my knowledge, there is not an OOTB way to achieve it, we have to write some custom code.

If you only want to the user can't see some items in list view base on some condition, we can use list view Filter to achieve it. Note:User also access item form through URL.

I suggest you use remote event receiver or azure function to achieve this requirement.

In classic site, we can also add some JavaScript code into master page to prevent users access edit form page and hide the delete button in the page.

1
votes

For this kind of requirement the solution which is 'no code' and with SP online is Power automate (previously MS Flow).

The best option in Your case would be to create a recurring flow which for example starts every day at 00:10 AM -> please see MS docs with description how to do this.

The Flow should get all items from a specific list for a specific site. You can do that with the 'Get Items' step. After that You can use the 'Apply to each' Step to check each item creation date with a 'Condition' Step. When some item will be older than one week You can use additional steps to break permission inheritance on item and remove all groups from permissions on this item or change the permissions on item from edit to read. Here I found an interesting article where are some predefined steps shown how to remove all permissions, remove and add a group. To tell You the truth I was not aware there already are this kind of steps in Power automate (maybe something new :) ) .

I would use SharePoint HTTP request and use SharePoint API to remove permissions on item and change some group role from edit to read. So I would do a similar procedure like here the only difference is not to break permission on all list but just on a specific item which I would get by ID. You can do all of those API request with a 'SharePoint HTTP request' Step

Please be aware there usually is a 5 000 unique permission levels threshold (50 000 is in on-prem) in list (place check here for latest info on limits in SP Online). So a better option would be to create a folder with view only permissions for the users before and when an item is older than one week You could only move this item to that folder also with Power Automate. That way all the files (items) in this folder would be read only and You would have only one unique item scope in this list and not as many as the old items.

Some other options You could use are:

  • Also code solution, but not RER and Azure function, would be to create a console app that uses CSOM to look through items in this list and either breaks permission on each item or moves to a folder (like the flow) and schedule this CSOM app on some local or remote server in Task Scheduler... Of Course You would need some local (or other) server for it which is always up and running :)
  • If You would like to use some 'little coding' and by any chance You are still using classic UI (not modern) You could use JSLink attached to CT or some column like Title and block editing of fields in edit forms etc (this is not the best option as always the users may create a view without a columns with this JSLink and go around this or modify the item using CSOM or Rest API)
1
votes

You might consider using PowerApps (In case you have it configured in your subscription) to customize the edit form,

Then you use the validate() method, and disable a user from submitting the form in case ("Created" + 7 days) <= Today() or something like that.