Posts Tagged ‘custom field’

My thanks to Peter Holpar for his blog post on “How to Override the Default Item Save Event Using Custom Fields.” Gave me the information I needed to create a handy custom field.

During our testing, though, we found that save errors were not being handled correctly. For example, when the “Allow duplicate values” was set to “No” and you tried to set a duplicate value in the field, you got a very ugly error page. So, I went back to Peter’s blog: No solution. I searched all over: no solution. So, back to Peter’s blog. There was one little tidbit that turned into the key to solving the problem and getting SharePoint to properly handle the SPDuplicateValuesFoundException. Peter mentioned an alternative to using SPContext.Current.ListItem.Update() was to use SaveButton.SaveItem(). Close, very close! The parameterless method is actually not available to our custom field, but SaveButton.SaveItem(SPItemContext, bool, string) is. Calling this method instead of the update method took care of the problem. Now, when someone tries to enter a duplicate value in our custom field, we get the nice, red message “This value already exists in the list.”

Now a happy Monday morning!


Read Full Post »