0

I used to have this problem some months ago using SharePoint 2010, now it's back (SP 2013). Unfortunately I cannot remember what my "solution" was back then.

Anyway I would be very grateful for some best practice recommendations.

Column validation (1): Below is the definition of a simple datetime field which I will re-use throughout this example. There's nothing really special about it. All that changes is the validation formula. More precisely the field references. Either I am using the field's display name or the field's internal name.

<Field ID="{CAFE3C31-C8DD-4917-98A9-0DE886177758}"
     Type="DateTime"
     Name="ClrExpirationDate"
     DisplayName="Expiration date"
     Group="$Resources:TtsIntranetClr,ColumnsGroupName"
     Required="FALSE" 
     Format="DateOnly"
     FriendlyDisplayFormat="Disabled"
     CalType="0">
  <Validation Message="Please select a date in the future or no date at all.">=OR([Expiration date]&gt;TODAY(), [Expiration date]=0)</Validation>
</Field>

Result: Create a new list, add the existing column. Create a new list item. Field validation works. However I don't think this approach will take me very far. What about localized field display names?! Validations should be based on the field's internal name - so let's try that instead...

Column Validation (2): Simple Column definition (exactly the same) - but [ClrExpirationDate] in the validation formula instead of the display name.

Result: Create a new list, add the existing colum -> FAIL! Really? Am I really supposed to use display names for field validation formulas? :( :(

Okay well then.. let's stick with display names then! Let's add the column to a content type and the content type to a list template.

List template column validation (1): The list's schema.xml looks like that:

[...]
<Field ID="{CAFE3C31-C8DD-4917-98A9-0DE886177758}"
       Type="DateTime"
       Name="ClrExpirationDate"
       DisplayName="Expiration date"
       Group="$Resources:TtsIntranetClr,ColumnsGroupName"
       Required="FALSE"
       Format="DateOnly"
       FriendlyDisplayFormat="Disabled"
       CalType="0">
    <Validation Message="Please select a date in the future or no date at all.">=OR([Expiration date]&gt;TODAY(), [Expiration date]=0)</Validation>
</Field>
[...]

As you can see, the validation formula is exactly the same as in the field definition above.

Result: Deploy the solution -> list instance is being created -> create a new list item -> date validation fails! "The validation formula has evaluated to an error."

...WTF? What worked perfectly fine before doesn't work in a list anymore? Really?

List template column validation (2): Same column, same content type, same list template. All I changed was the validation formula to use the field's internal name this time. So the schema.xml now looks like that:

[...]
<Field ID="{CAFE3C31-C8DD-4917-98A9-0DE886177758}"
       Type="DateTime"
       Name="ClrExpirationDate"
       DisplayName="Expiration date"
       Group="$Resources:TtsIntranetClr,ColumnsGroupName"
       Required="FALSE"
       Format="DateOnly"
       FriendlyDisplayFormat="Disabled"
       CalType="0">
    <Validation Message="Please select a date in the future or no date at all.">=OR([ClrExpirationDate]&gt;TODAY(), [ClrExpirationDate]=0)</Validation>
  </Field>
[...]

Result: Deploy solution -> list instance is being created -> create a new list item -> date validation works! Surprise surprise...

How's that? And how am I supposed to deal with that? Does it really boil down to editing schema.xml myself? It's not a big deal - I just need to know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.