Posted by: R Manimaran | April 28, 2011

Creating Date Type Site Column with Default value using Feature in SharePoint 2007

Creating Date Type Site Column with Default value using Feature in SharePoint 2007

Most of the time, while I am creating a Site column of type Date, I used to create site column without default value.  But this time I came with creating a site column with some default values.

That is when creating new list item I like to have to (Today date+10 ) as a default value.

When we create the site columns using SharePoint UI we use to find calculated column in a Default values section of DateTime. So there will be a way to create it using Feature. So here is an example to create DateTime column with some default values.

Feature.xml

<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="C0104E82-8FEB-4bd5-B5C2-07BFB9CE6F0E"
	xmlns="http://schemas.microsoft.com/sharepoint/"
	Title="MySiteColumns"
	Description="My Site Columns"
	Scope="Site">
<ElementManifests>
	<ElementManifest Location="Elements.xml"/>
</ElementManifests>
</Feature>

Elements.xml

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
	<Field Type="DateTime"
                 DisplayName="MyDate1"
                 Required="FALSE"
                 Format="DateOnly"
                 Group="My Group"
                 ID="{49FC8563-0729-4c8a-A46A-7F504C357FCF}"
                 StaticName="MyDate1" Name="MyDate1">
	  <DefaultFormula>=[Today]+10</DefaultFormula>
	</Field>
	<Field Type="DateTime"
                 DisplayName="MyDateTime1"
                 Required="FALSE"
                 Format="DateTime"
                 Group="My Group"
                 ID="{6F023C0D-1B03-4d9b-9F1D-37CCE61AE19B}"
                 StaticName="MyDateTime1"
                 Name="MyDateTime1">
	 <DefaultFormula>=[Today]+2+"13:00"</DefaultFormula>
	</Field>
	<Field Type="DateTime"
                 DisplayName="MyDate2"
                 Required="FALSE"
                 Format="DateOnly"
                 Group="My Group"
                 ID="{60E37A84-15EA-4f3e-B3AB-E3D40D9F728F}"
                 StaticName="MyDate2"
                 Name="MyDate2">
	  <Default>[today]</Default>
	</Field>
</Elements>

So in the above three Date site column I like to have a default of date is the 10 days greater than the item created date.

Second is a DateTime column with Created Date +2 days as default date. It also has 1:00 PM as the default time value.

Third is I like to have current Date as default value.  Below is the List which uses the above  site columns. So when I create a new List Item my new form will have the default date and time gets populated.

Advertisements

Responses

  1. Nice info


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: