Wednesday, May 30, 2007

Deploying a calculated site column using a feature in SharePoint 2007

It is not very easy to find a sample of how to define a site column of type calculated using the SharePoint 2007 features framework. The documentations shows how to do it using the user interface (see Calculate data in lists or libraries ). The documentation in the WSS SDK about the  Formula Element in the CAML Core Schemas points in the right direction but is maybe not clear enough. I tested the sample code below by using the site columns in a list definition. You might want to test it out in a content type as well - please provide feedback in the comments.

Code sample feature.xml

<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="" Scope="Site" Title="Calculated Sitecolumn" Id="49C90DCA-6C76-4b30-99DB-7C4C7D100761">
<ElementManifest Location="calcsitecolumn.xml"/>

Code sample calcsitecolumn.xml

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="">
<Field Name="CalcDemo" StaticName="CalcDemo"  Type="Calculated" DisplayName="Calculated column" ID="{DD01AF0E-5E58-4e50-B3E8-1BFC866CA9A0}" ResultType="DateTime" Format="DateOnly" ReadOnly="TRUE">
<FieldRef Name="StartDate" ID="{64cd368d-2f95-4bfc-a1f9-8d4324ecb007}" />

Have fun with it ...





Saurabh Mishra said...

Is it possible to create a custom formula that could be referenced by a calculated field?

For example, would it be possible to create a formula called ReplaceAll which would replace all instances of a sub-string in a string with another sub-string.

Any thoughts??


komakino said...

I was looking for a solution like this. I know my mistake now. Thanks for sharing ;)

Sachin said...

Can you share the demo as i have done same thing as per your demo but i am not able to see my site column in site column gallary

aneel said...


I trying to create feature to deploy or manage a site column which is derived from a custom field type. But the problem here is the Custom field type takes a string parameter called MetadataType. I need to pass it to the custom field type to create a site column, But couldnt find any resource how to go about it.
How to pass a value to the field type property

Thanks in advance

Munish Gumber said...

Try this :




Munish Gumber said...