Click here to monitor SSC

Charles Lee

SharePoint: Numeric/Integer Site Column (Field) Types

Published Monday, March 01, 2010 10:00 AM

What field type should you use when creating number based site columns as part of a SharePoint feature?

Windows SharePoint Services 3.0 provides you with an extensible and flexible method of developing and deploying Site Columns and Content Types (both of which are required for most SharePoint projects requiring list or library based data storage) via the feature framework (more on this in my next full article.) However there is an interesting behaviour when working with a column or field which is required to hold a number, which I thought I would blog about today.

When creating Site Columns in the browser you get a nice rich UI in order to choose the properties of this field:

image

image

However when you are recreating this as a feature defined in CAML (Collaborative Application Mark-up Language), which is a type of XML (more on this in my article) then you do not get such a rich experience.  You would need to add something like this to the element manifest defined in your feature:

<Field SourceID="http://schemas.microsoft.com/sharepoint/3.0"
       ID="{C272E927-3748-48db-8FC0-6C7B72A6D220}"
       Group="My Site Columns"
       Name="MyNumber"
       DisplayName="My Number"
       Type="Numeric"
       Commas="FALSE"
       Decimals="0"
       Required="FALSE"
       ReadOnly="FALSE"
       Sealed="FALSE"
       Hidden="FALSE" />

OK, its not as nice as the browser UI but I can deal with this.

Hang on.

Commas="FALSE" and yet for my number 1234 I get 1,234.  That is not what I wanted or expected.  What gives?

The answer lies in the difference between a type of "Numeric" which is an implementation of the SPFieldNumber class and "Integer" which does not correspond to a given SPField class but rather represents a positive or negative integer.  The numeric type does not respect the settings of Commas or NegativeFormat (which defines how to display negative numbers.)  So we can set the Type to Integer and we are good to go.  Yes?

Sadly no!

You will notice at this point that if you deploy your site column into SharePoint something has gone wrong.  Your site column is not listed in the Site Column Gallery.  The deployment must have failed then?  But no, a quick look at the site columns via the API reveals that the column is there.  What new evil is this?  Unfortunately the base type for integer fields has this lovely attribute set on it:

UserCreatable = FALSE

So WSS 3.0 accordingly hides your field in the gallery as you cannot create fields of this type.

However!

You can use them in content types just like any other field (except not in the browser UI), and if you add them to the content type as part of your feature then they will show up in the UI as a field on that content type. 

Most of the time you are not going to be too concerned that your site columns are not listed in the gallery as you will know that they are there and that they are still useable. So not as bad as you thought after all.  Just a little quirky.  But that is SharePoint for you.

You need to sign in to comment on this blog

About CharlesLee

Charles Lee is a software solutions developer for a large law firm based in Birmingham in the UK. He has been developing with ASP.NET since 2003, and currently focuses on WSS 3.0 and MOSS 2007 solutions to complex business problems.
<March 2010>
SuMoTuWeThFrSa
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
How to Kill a Company in One Step or Save it in Three
 The majority of companies that suffer a major data loss subsequently go out of business. David Wesley... Read more...

Migrating from OCS 2007 R2 to Lync: Part 4
 Having migrated the rest of our users and legacy resources across, and start getting ready to... Read more...

Automated Script-generation with Powershell and SMO
 In the first of a series of articles on automating the process of building, modifying and copying SQL... Read more...

Seth Godin: Big in the IT Business
 Seth Godin has transformed our understanding of marketing in IT. He invented the concept of 'permission... Read more...

Using SQL Test Database Unit Testing with TeamCity Continuous Integration
 With database applications, the process of test and integration can be frustratingly slow because so... Read more...