Conditional requiring of fields using SharePoint 2010 List Validation

My customer wanted to be able to make a field required only if another field had a specific value, AKA Conditional Requiring.   While SharePoint has the ability to make fields required (or even check for uniqueness) it still does not yet have the ability to make a field required based on another.  That is where List Validation comes in.


If you do not already know, List Validation (along with Column Validation) allows you to perform checks on fields to make sure that they pass certain requirements.  They can be as simple as checking to make sure a field has a specific value to some rather complex (and cool) validations.  I forget who did it but I saw a “poor man” validation to make sure a human was entering a comment by making sure they entered in the first 3 letters of the today’s day.


Here is my setup.  I have two different fields, FieldA and Field B.   The field names have been changed to protect the innocent :)   They are both choice fields, although I would think they could be just about any field type,***certain fields like LOOKUP will not work here and the fields do not actually show up in the validation settings form*** and FieldA is required while FieldB is not.  I also setup FieldB so it does not have any default value.


 In my case I need to check two different things.  The first was that FieldA contained a specific value and if it did (and only if it did) I needed to make sure that FieldB had a selected value.  The first part is simple:


=[FieldA]=”ShareBlog”


This just states that if FieldA has the value of “ShareBlog” then the validation passes, otherwise it fails.  If you want to ouput text, rather than just check to see if it validation passes you can use the IF function.  The above formula can be rewritten as:


=IF([FieldA]=”ShareBlog”,”Pass”,”Fail”)


This also checks to see if FieldA has the value of “ShareBlog” but in this case it will ouput “Pass” if it does or “Fail” if it doesn’t.   Pretty close to what I need but not quite there.  I could also use:


=IF([FieldA]=”ShareBlog”,”True”,”False”)


but this will just output “True” or “False” (and the validation will actually still fail).   Finally I realized I can take the quotes off of “True” and “False” and just use the static names.   Now I will get my validation to pass if FieldA has the value of “ShareBlog” again.  Almost there.


Now I just need to check to make sure that FieldB has a value.   That is simple enough:


=IF([FieldB]<>””,True,False)


What I need to do now is to embed the two IF statements together to create the new one:


=IF([FieldA]=”ShareBlog”,IF([FieldB]<>””,True,False),True)


Sharp eyed readers may have notticed that for the outter IF statement I am actually returning TRUE no matter if FieldA has the value of “ShareBlog” or not.   That is not quite true.   If FieldA DOES contain “ShareBlog” then I want to make sure that FieldB has a value so I go into the second IF statement which will return a TRUE if FieldB has a value or FALSE if it doesn’t.   If FieldA DOESN’T contain “ShareBlog” then I don’t care what FieldB has for a value so I will always return TRUE.


That should do it.   You can throw some AND functions in there as needed if you need to check more fields

2 thoughts on “Conditional requiring of fields using SharePoint 2010 List Validation”

  1. Enjoyed your article. I’m working with a SP list that needs to have validation to ensure if a certain value is selected for item type, the title must NOT be unique. This is being used to link together Parent and Child items in my list.

    Column A – Title (multiple lines of text)
    Column B – Item type (choice: n/a, Parent, Child)

    I’m trying to enforce that if Column B is set to “Child” then Column A must match an existing Title in the Sharepoint list.

    I would appreciate any direction you can give me in solving this issue.

Leave a Reply

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


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>