locked
Best Practice? - Workflow or Feature? RRS feed

  • Question

  • If I wanted to make a list item un-editable 24 hours after entry, what would be the best way to accomplish this?

    I could write a Feature that checks the "Modified Date" vs. the current date before allowing chagnes or deletions. 

    Or could I write a workflow that's assigned to each item to change it's permissions after the 24 hours?

    Or is there a better way?

    thanks for your vote!

    -JS

    Tuesday, February 19, 2008 1:27 AM

Answers

  • Why not create an ItemUpdating event handler which would cancel the updation during that specified period.

    Madhur
    Tuesday, February 19, 2008 3:34 AM
  •  

    To fulfil this requirement, ItemUpdating Event Handler is best choice. You can cancel the event based on your required business formula. This way user will try to Edit the Item but when they will hit save, it will not allow them to save. You can deploy your event handler through a Feature.

     

    Similarly you should also use ItemDeleting Event if there is requirement to block deletion after a certain amount of time.

     

     

    Regards,

     

    BizWorld

    Tuesday, February 19, 2008 8:15 PM
  • You can also register the event handler through Sharepoint Object Model code. I adopted this approach as well in one scenario where i create one ASPX page and i placed two buttons on it to Display Existing event handlers of all document library, lists etc and another button to Register the event handler. i created a new folder in 12 hive Template\Layouts folder and i placed my aspx file in it and placed my dll into Bin folder of sharepoint web application. this page can be accessed using http://myspsServer/_layouts/mycustomApp/mypage.aspx so in this case mycustomApp was the folder which i created in layout folder.   i use this page now to see what are my existing event handlers and i use it also to register my event handler.

     

    This all above is a another way to register the event handler.

     

    BizWorld

    Wednesday, February 20, 2008 7:06 PM

All replies

  • Hi Jessica,

     

    Not sure how you would implement the feature since it would have to be activated/deactivated in order for the custom logic to run.  Some approaches that come to mind are:

     

    1. Custom timer job that can be scheduled to run every hour or so and look for items that are 24 hours old.  The lists to scan could be read from a configuration file stored on the server
    2. Custom workflow in conjunction with the Information Rights Management settings on the item.  You could set the item to expire 1 day after creation and upon exipration start a workflow.  The workflow would remove all permissions from the item, granting only read-only access to users

    Option #1 is a clean solution, the only problem is that there may be a delay equal to the interval the timer job is set to run.  Option #2 is also a nice solution, and introduces no delay (or at least a very small one).  Again, the idea here is that we need to have the logic that turns off permissions executed automatically, so not sure how the feature would work in this case.  That's my $0.02, and I would love to hear what other ideas are out there.  If you need some help on how to implement these, just let us know.

     

    Ryan Ramcharan

     

     

    Tuesday, February 19, 2008 2:22 AM
  • Why not create an ItemUpdating event handler which would cancel the updation during that specified period.

    Madhur
    Tuesday, February 19, 2008 3:34 AM
  •  

    To fulfil this requirement, ItemUpdating Event Handler is best choice. You can cancel the event based on your required business formula. This way user will try to Edit the Item but when they will hit save, it will not allow them to save. You can deploy your event handler through a Feature.

     

    Similarly you should also use ItemDeleting Event if there is requirement to block deletion after a certain amount of time.

     

     

    Regards,

     

    BizWorld

    Tuesday, February 19, 2008 8:15 PM
  • Hi Jessica,

     

    I guess I will have to stop answering posts late at night Smile  I completely overlooked the fact the handling the ItemUpdating event will work.  I was thinking that there had to be some automated process in which all items would be set to read only.  So I will have to agree with BizWorld, that having an ItemUpdating that cancels the event if the current time is greater than 24 hours from the document creation date is the best solution.  You could also remove user access to the item inside of this event handler. 

     

    Ryan 

     

    Tuesday, February 19, 2008 9:43 PM
  • Is a "Feature" the only way to do something like this (override the ItemUpdating method)?

    There are no other ways to play with Event Handlers in SharePoint, are there?

     

    Thanks Everyone for the Input.  I was going to go with the Workflow but I think you guys are right and a "Feature" would be cleaner.  There will be 50+ entries a day in this "security log" and that would be a lot of Workflows running.

     

    -JS

     

     

    Wednesday, February 20, 2008 5:08 PM
  • You can also register the event handler through Sharepoint Object Model code. I adopted this approach as well in one scenario where i create one ASPX page and i placed two buttons on it to Display Existing event handlers of all document library, lists etc and another button to Register the event handler. i created a new folder in 12 hive Template\Layouts folder and i placed my aspx file in it and placed my dll into Bin folder of sharepoint web application. this page can be accessed using http://myspsServer/_layouts/mycustomApp/mypage.aspx so in this case mycustomApp was the folder which i created in layout folder.   i use this page now to see what are my existing event handlers and i use it also to register my event handler.

     

    This all above is a another way to register the event handler.

     

    BizWorld

    Wednesday, February 20, 2008 7:06 PM
  • Wow.  OK.  I think I understand.  So technically I could write and compile a dll with the Event Handler, place it in my applications Bin folder, and just write a console app that registers it within sharepoint? (although I admit an ASPX page would be nicer).  Pretty cool.  I'm going to have to try this out.

    Thanks,

    -JS

     

    Wednesday, February 20, 2008 9:48 PM