How can I set the default value for a custom "Number" field in SharePoint?

Posted by UnhipGlint on Stack Overflow See other posts from Stack Overflow or by UnhipGlint
Published on 2010-03-16T14:12:42Z Indexed on 2010/03/16 14:16 UTC
Read the original article Hit count: 269

Filed under:
|
|
|

I created a custom field for a content type I am creating using the XML below.

<field ID="{GUID}" Required="False" DisplayName="Likes" Name="Likes" Type="Number" SourceID="http://schemas.microsoft.com/sharepoint/v3"><default>0</default></field>

The field is meant to be used as a counter of sorts, and will be incremented programmatically. But, I can't get the value to default to "0" when a new item is created. However, for some reason, when I create a new column manually using the Site Collection settings page and configure it to default to "0" it works as it should.

So far, I've tried the following tactics:

  • I removed the "default" element from the field definition, and set the "DefaultValue" attribute on the content type definition.
  • I exported a definition for the manually-created, working column (using an Imtech STSADM tool). Then, I added it to my field definitions XML and modified the IDs so that I could add it to my content type. When I did this, it still didn't work, even though it was exported from a working column!

Any idea why this isn't working for me?

© Stack Overflow or respective owner

Related posts about wss

Related posts about sharepoint