locked
Is it possible: List Validation based on column in another list RRS feed

  • Question

  • Hi,

    Problem: I need to prevent users from adding a record to one list based on a value in another list.

    I use SP2010 standard. I have 2 lists:

    • Edition list
    • Article list

    The edition list has a Title and a AddArticlesUntil (DATE) column. This column determines until what date&time(!) articles can be added to this edition.

    The Article list has a Title, BelongsToEdition and Content column. The BelongsToEdtion column is a lookup to the Edition.Title column.

    I need to restrict users from adding an article to a edtion when AddArticlesUntil is passed.

    • I (think  I) cannot use Validation Settings for the Articles list because the AddArticlesUntil is in another list
    • I would like users to get the "Thou added thein contribution to late" message before they add the content (which could be several pages of text) and press save
    • I tried using an EventReceiver OnItemAdding but than the item does not yet exist and I cannot get it to work and the user would be prompted at the moment they press save.

    Hope this makes sence :-)

    Wednesday, December 8, 2010 8:40 AM

Answers

  • Hi,

     

    I think an EventReceiver OnItemAdding can achieve your requirement.

    When you are adding an new item to Article list, the OnItemAdding will fire.

    And then get AddArticlesUntil column of the item from Edition list by comparing the column BelongsToEdition from Article list.

    If AddArticlesUntil is passed, prompt and prevent  the user from saving the item.

     

    If I misunderstood you, please let me know.

    Hope this helps

     

    Thanks!

    Stanfford


    Everything will be fine.
    • Proposed as answer by Venkatx7 Thursday, December 9, 2010 7:21 AM
    • Marked as answer by sander_d Friday, December 10, 2010 6:49 AM
    Thursday, December 9, 2010 6:44 AM

All replies

  • Hi,

     

    I think an EventReceiver OnItemAdding can achieve your requirement.

    When you are adding an new item to Article list, the OnItemAdding will fire.

    And then get AddArticlesUntil column of the item from Edition list by comparing the column BelongsToEdition from Article list.

    If AddArticlesUntil is passed, prompt and prevent  the user from saving the item.

     

    If I misunderstood you, please let me know.

    Hope this helps

     

    Thanks!

    Stanfford


    Everything will be fine.
    • Proposed as answer by Venkatx7 Thursday, December 9, 2010 7:21 AM
    • Marked as answer by sander_d Friday, December 10, 2010 6:49 AM
    Thursday, December 9, 2010 6:44 AM
  • Thnx for the reply!

    This should do the trick although I'm stuck with properties.ListItem bein' NULL but maybe I can use properties.AfterProperties["FieldInternalName"]. Haven't tested that really

    BUT

    From a user perspective this is a #%@ solution. You first type in all the info and THEN you are being to told you are to late....

    Is it possible to check this on....PING...just had a brainwave. Is it possible to check it with a custom Add New Item?!!

    Any thoughts on that?

    Thursday, December 9, 2010 8:44 AM
  • From a user perspective this is a #%@ solution. You first type in all the info and THEN you are being to told you are to late....

    You are right, it’s by design and you have to type all information.

    If the user can’t accept this solution, I afraid you have to consider other solution like creating custom filed type

    For more information, please refer to

    http://msdn.microsoft.com/en-us/library/gg132914.aspx

    For further development, please feel free to ask question in proper forum

    http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/threads


    Everything will be fine.
    Friday, December 10, 2010 2:39 AM