Pages

Tuesday, April 10, 2012

List and Field Validation SharePoint 2010

List validation and Field validation are new addition in SharePoint 2010.  This is good because as promised by Microsoft this is a step in right direction for code less or minimal code SharePoint. Before in order to achieve a date validation where user should enter a date greater than today developers had to either create custom pages or find ways like JavaScript etc. Creating a custom pages or web part is not a daunting tasks but these changes will come and haunt us during migration. Now with field validation and List validation the tasks has become simple and takes SharePoint a notch closer to complete Enterprise Content Management system. Further this is much more useful in SharePoint online and Sand Boxed Solution where GAC access and Layout access is not possible.

List field validation uses formula similar to the calculated field values.

Example :

Validate Date fields

If you want to validate start date and end date in the Tasks list and want to prevent user entering end date less than start date this could be easily achieved using List validation.


 Under Validation Setting formula for validating the column can be specified.In this case I am using due date and the condition I am validating is due date should be greater than start date.

The user Message is used for displaying the error message. But there one draw back which I hope Microsoft will address in future releases SharePoint 2012.

You can specify multiple condition either using OR or AND. but adding specific error message become difficult which if Microsoft provides a better way would be much needed and nicer approach.






Field Validation

Field validation is one of the most useful feature added in SharePoint. The reason for this is it reduces the amount of custom code that needs to be written and also give more control on the field level, though there is no Field Level Security OOTB SharePoint. Field Level validation uses the formula similar to the List Validation, but a subtle difference exists. In the Field Validation you cannot compare the current field with other fields. The purpose of field validation is to validate and restrict entry on current field. If you want to compare 2 different field then you have to use List Validation where you can use AND and OR to include with existing Validation. By Default List Validation does an AND with existing conditions.

In the picture below I am validating Due Date field on the Task ContentType. The condition that needs to be satisfied is Due Date should be greater than Today.






You can find all formula that can be use here