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:
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:
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:
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:
What I need to do now is to embed the two IF statements together to create the new one:
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