For some time I’ve been teased by the new SharePoint 2010 List Item Validation setting and the other day I had a problem that I thought could be solver by using ListItem Validation:
“An end-user adds or edits a List Item with business data that needs to be compliant with Business Rules”
Unfortunately I found List Item Validation inadequate in the first business case I could have use for it, but a Brainfart™ also provided me with an adequate workaround.
List Item Validation can easily be configured in SharePoint 2010 Lists. For a great sample of how Validation can be configured have a look at Chack’s post. Also Be aware that you can use the full set of Calculated Field Formulas which is a powerful and not too document addition to common ListItem Validation.
Problems with the common solution
As with many new features in the extensive development platform that SharePoint 2010 is there’s normally a catch. I actually wanted to perform validation on the following:
If Tender r.b. Submitted = Yes then Project Type and Proposal Responsible can’t be empty.
Apparently there are many unsupported Column/Field Types for validation. So basically out of 9 fields only 4 of them can be used in a validation expression while any attempt to write column names of unsupported columns will give you an error:
“One or more column references are not allowed, because the columns are defined as a data type that is not supported in formulas.”
At Least the following Column types can’t be used for validation:
- Multipe lines of text
- Person or Group
- Managed Metadata
When there’s a problem there’s normally also a solution. At first I wanted to see if I could use an event receiver on the content type / List Definition too do some sort of server validation and return a friendly error message. To my surprise List Item Validation is not part of the Server Object Model.
Another thing also surprised me. List Item Validation could have been implemented by Microsoft as a part of the eventing pipeline, but it’s actually performed outside of it and even worse it’s done after the Before Events (e.g ItemAdding or ItemUpdating)
Luckily that also became the solution to my problem. While you could perform validation and cancel the event in the before event which would give the user an ugly error message and make him loose all his changes. The real simple solution is to add a Field to the list which is invisible to the end user
In any before event create your own Validation Method which only have your coding skill/imagination as limits but which will toogle the IsValid column to a false state.
Adequate workaround but requires coding, proper deployment unit’s etc but Highly required for medium complex scenarios. Enjoy