SharePoint: integer field doesn’t appear in site columns
This article presents a little SharePoint weirdness that you might encounter when you try to add the column of the SPFieldType
Integer
to the site columns collection.
The following line seems perfectly fine in Visual Studio, the code compiles and throws no exception at runtime:
1 |
web.Fields.Add("myField1", SPFieldType.Integer, false); |
However, the column created this way does not show in Site Columns gallery (available on Site Settings → Web Designer Galleries section → Site Columns, or when you append /_layouts/15/mngfield.aspx
to your site’s URL).
The reason for this was decribed in Charles Lee’s article who tracked down this behaviour to be the result of Integer’s base class property UserCreatable
set to FALSE
. He shows that this behaviour is present in WSS 3.0 for integer fields defined in feature’s CAML. I can confirm that this behaviour is still present in SharePoint 2013 and while SharePoint object Model allows to successfuly create such columns in C# or PowerShell, they are not visible in GUI.
The solution is to use Numeric
datatype instead of Integer
. While SPFieldType.Integer
was not intended to be used by developers and users, the Numeric
type does not have this problems and appear wherever it should in SharePoint UI.
Thank you! I was trying to figure out this issue for a day and half before finally finding your post! Works like a charm now!