Conditional Validation of fields using SharePoint 2010 List Validation


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

 

Source : http://msmvps.com/blogs/shareblog/archive/2012/02/28/conditional-requiring-of-fields-using-sharepoint-2010-list-validation.aspx

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: