Another great improvement in SharePoint 2010 is that now you can specify formulas that validate the columns based on other columns!
Let me take you through an example.
Here is a simple list called
It stores the student scores for Paper 1 – Paper 5 , total score and the result. The scores are values between 1 to 100.
[ This is still doable without any formulas by setting the maximum and minimum values for the Number column. But I am using this example to illustrate the Column Validation. But there is still one advantage of using validation than using the maximum and minimum setting 🙂 ]
Let us add a new item:
Looking at it, it is obvious that has a score of and is invalid. So, we should be showing some error messages so that users get notified that the information entered is invalid.
In SharePoint, now columns have a new section called where you can enter formulas (similar to Excel formulas) to pass validation.
You can enter the formula and the corresponding message that you want to display to the users if the validation fails. [You can customize the error message the way you want if you this validation than using the maximum and minimum settings 🙂 ]
The formula is pretty similar to Excel. I also remember seeing some SharePoint functions (in the early builds), but the help is currently unavailable so we have to wait till the public beta is released.
Remember, this is a column validation and not list validation, so if its created at the site level, it will apply everywhere.
You can do the same thing at the list level. You can access this in the List settings page:
The only difference is now you know what are the columns you would be validating against.
Here is validation in action:
Notice how it changes the focus and also displays the error message below that particular column.
For the developers out there, here is how you can set the validation formula and message via object model:
(SPSite spSite = SPSite())
(SPWeb spWeb = spSite.RootWeb)
SPList lstScores = spWeb.Lists.TryGetList();
(lstScores != )
SPFieldNumber fldPaper1 =
Note: is a new method which you can safely use to get a object. If the list doesn’t exists, it returns null.