locked
Is it possible to set a default value to a column in a content type? RRS feed

  • Question

  • We have a parent content type which has a column (let's call it "field1").

    We hav some content types which inhertits this parent content type, and in each of them the column "field1" should be set to a different default value.

    is it possible to define that?


    keren tsur
    Monday, December 26, 2011 3:01 PM

Answers

  • I created a site content type based on the Item content type, add a column from new site column named DV1, set the default value of the column, what follows is the definition i get from SharePoint 2010 manager v2 alpha:

    <ContentType ID="0x01008703E91F1C794C43991A9D06DA4CB247" Name="CTdefaultValue" Group="Custom Content Types" Version="1">
      <Folder TargetName="_cts/CTdefaultValue" />
      <Fields>
        <Field ID="{c042a256-787d-4a6f-8a8a-cf6ab767f12d}" Name="ContentType" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="ContentType" Group="_Hidden" Type="Computed" DisplayName="Content Type" Sealed="TRUE" Sortable="FALSE" RenderXMLUsingPattern="TRUE" PITarget="MicrosoftWindowsSharePointServices" PIAttribute="ContentTypeID" Customization="">
          <FieldRefs>
            <FieldRef ID="{03e45e84-1992-4d42-9116-26f756012634}" Name="ContentTypeId" />
          </FieldRefs>
          <DisplayPattern>
            <MapToContentType>
              <Column Name="ContentTypeId" />
            </MapToContentType>
          </DisplayPattern>
        </Field>
        <Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Title" Group="_Hidden" Type="Text" DisplayName="Title" Required="TRUE" FromBaseType="TRUE" Customization="" ShowInNewForm="TRUE" ShowInEditForm="TRUE" />
        <Field Type="Text" DisplayName="DV1" Required="FALSE" EnforceUniqueValues="FALSE" Indexed="FALSE" MaxLength="255" Group="Custom Columns" ID="{a7fef97f-2d86-4dbb-af64-3fd46e0d0f62}" SourceID="{560e13b7-0c17-47df-973c-50c3a4222ac8}" StaticName="DV1" Name="DV1" Customization="">
          <Default>defaultValue1</Default>
        </Field>
      </Fields>
      <XmlDocuments>
        <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
          <FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
            <Display>ListForm</Display>
            <Edit>ListForm</Edit>
            <New>ListForm</New>
          </FormTemplates>
        </XmlDocument>
      </XmlDocuments>
    </ContentType>

    • Marked as answer by GuYuming Thursday, December 29, 2011 3:45 AM
    Tuesday, December 27, 2011 7:47 AM
  • Hi Keren -

    You're not going to be able to set two different default values for the same Site Column that is used in two different content types. You can, however, set the default value at the list level once you assign the content type to be used on a list.

    Hope that helps.

    Ryan


    http://blog.randomdust.com
    • Marked as answer by GuYuming Thursday, December 29, 2011 3:44 AM
    • Unmarked as answer by GuYuming Friday, December 30, 2011 1:32 AM
    • Marked as answer by GuYuming Friday, December 30, 2011 1:32 AM
    Wednesday, December 28, 2011 7:13 PM
  • The thing is that i'm using those content types in the same document library...

    (There is a mapping between content type to a metadata, and that's what i tried to achieve. For example if the Document is a "Design Review" template (that's why i used content type - to set the pptx template...) - The metadata "Type of document" should be "Design Review"...


    keren tsur
    Custom code is going to be your only option, then. Probably an event receiver on the library, or a workflow on the content type, that updates the value of that column programatically.

    http://blog.randomdust.com
    • Marked as answer by GuYuming Friday, December 30, 2011 1:32 AM
    Thursday, December 29, 2011 6:39 PM

All replies

  • Hi Keren,

    The default value is set on the column and not via the CType.

    As an Example of the defualt choice being No.

      <Field Type="Choice" DisplayName="Biosequence Data" Required="FALSE" Format="RadioButtons" FillInChoice="FALSE" Group="AGN" ID="{1b2ee626-0cc4-40f8-80d2-abdcc3576a0a}" SourceID="{d955a1e9-4fbc-424f-92e5-fd3afd793099}" StaticName="BiosequenceData" Name="BiosequenceData" Description="Includes Biosequence Data?   &#xD;&#xA;(If Yes, automatic review by the SVP, Biological Sciences)">
        <Default>No</Default>
        <CHOICES>
          <CHOICE>Yes</CHOICE>
          <CHOICE>No</CHOICE>
        </CHOICES>
      </Field>
    

    Happy Holidays.

     

     

    -Ivan

     

     


    Ivan Sanders My LinkedIn Profile, My Blog, @iasanders.
    Monday, December 26, 2011 3:18 PM
  • We don't want to use code.

    The thing is that there is a default value which depends on the content type.

    Did you mean via the column: the site column / the library column?

    In our case we set the column as a part of the content type, and than it's automatically set a site column - and the site column enables only single definition of a default value...

    (the behavior i want to achieve is something like the behavior of "default columns values" which i may set on a folder in a document library)


    keren tsur
    Monday, December 26, 2011 4:10 PM
  • I created a site content type based on the Item content type, add a column from new site column named DV1, set the default value of the column, what follows is the definition i get from SharePoint 2010 manager v2 alpha:

    <ContentType ID="0x01008703E91F1C794C43991A9D06DA4CB247" Name="CTdefaultValue" Group="Custom Content Types" Version="1">
      <Folder TargetName="_cts/CTdefaultValue" />
      <Fields>
        <Field ID="{c042a256-787d-4a6f-8a8a-cf6ab767f12d}" Name="ContentType" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="ContentType" Group="_Hidden" Type="Computed" DisplayName="Content Type" Sealed="TRUE" Sortable="FALSE" RenderXMLUsingPattern="TRUE" PITarget="MicrosoftWindowsSharePointServices" PIAttribute="ContentTypeID" Customization="">
          <FieldRefs>
            <FieldRef ID="{03e45e84-1992-4d42-9116-26f756012634}" Name="ContentTypeId" />
          </FieldRefs>
          <DisplayPattern>
            <MapToContentType>
              <Column Name="ContentTypeId" />
            </MapToContentType>
          </DisplayPattern>
        </Field>
        <Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Title" Group="_Hidden" Type="Text" DisplayName="Title" Required="TRUE" FromBaseType="TRUE" Customization="" ShowInNewForm="TRUE" ShowInEditForm="TRUE" />
        <Field Type="Text" DisplayName="DV1" Required="FALSE" EnforceUniqueValues="FALSE" Indexed="FALSE" MaxLength="255" Group="Custom Columns" ID="{a7fef97f-2d86-4dbb-af64-3fd46e0d0f62}" SourceID="{560e13b7-0c17-47df-973c-50c3a4222ac8}" StaticName="DV1" Name="DV1" Customization="">
          <Default>defaultValue1</Default>
        </Field>
      </Fields>
      <XmlDocuments>
        <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
          <FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
            <Display>ListForm</Display>
            <Edit>ListForm</Edit>
            <New>ListForm</New>
          </FormTemplates>
        </XmlDocument>
      </XmlDocuments>
    </ContentType>

    • Marked as answer by GuYuming Thursday, December 29, 2011 3:45 AM
    Tuesday, December 27, 2011 7:47 AM
  • Hi Keren,

    But ou cant use the same field twice with two different defaut values 

        <Field Type="Text" DisplayName="DV1" Required="FALSE" EnforceUniqueValues="FALSE" Indexed="FALSE" MaxLength="255" Group="Custom Columns" ID="{a7fef97f-2d86-4dbb-af64-3fd46e0d0f62}" SourceID="{560e13b7-0c17-47df-973c-50c3a4222ac8}" StaticName="DV1" Name="DV1" Customization="">
          <Default>defaultValue1</Default>
        </Field>
    
    

    Example of CType
    <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <ContentType ID="0x010100EB3FB001B91B9B44B278F041C671C28F" Name="AGN.RD" Group="AGN" Description=""">
        <FieldRefs>
          <RemoveFieldRef ID="fa564e0f-0c70-4ab9-b863-0177e6ddd247" Name="Title" />
          <FieldRef ID="9255a2a1-2c7c-42b7-b341-6d501f297f94" Name="ManuscriptTitle" Required="TRUE" />
          <FieldRef ID="0ce210bc-af4b-4cb8-b6a1-f815e5289496" Name="LeadAuthor" Required="TRUE" />
          <FieldRef ID="c423b3d2-b2cf-4129-833d-577a855f4860" Name="AdditionalAuthors" />
          <FieldRef ID="c59743d0-f4d8-4027-93ea-c971d74428d7" Name="ClinicalDevelopment" Required="TRUE" />
          <FieldRef ID="43cb2c5c-a7ef-4c48-b4a8-a615560c37fb" Name="NonClinical" Required="TRUE" />
          <FieldRef ID="449edc77-097f-4fe3-8921-76dfd47011e6" Name="NonClinicalMethodology" Required="TRUE" />
          <FieldRef ID="d99b162b-775a-4f7e-9120-74a8af955925" Name="PublicationType" Required="TRUE" />
          <FieldRef ID="8c50e084-4437-4925-bb5c-7580641e5713" Name="Publication" Required="TRUE" />
          <FieldRef ID="1a91985b-d8ba-4b2f-98a0-2fe143daaca2" Name="DateNeeded" Required="TRUE" />      
       </FieldRefs>
      </ContentType>
    </Elements>
    

    Though as you have seen you can mix Ctype Features and SiteColumn Features together, However, I keeep them seperate in seperate element files.

     

    I would Hide Field1 from the 2nd CType, create a Field2, Change the default value, and change the DisplayName to Field1.

     

    Happy Holidays

     

    -Ivan

     

     

     


    Ivan Sanders My LinkedIn Profile, My Blog, @iasanders.
    Tuesday, December 27, 2011 8:28 AM
  • Hi,

    We try to use the UI with no code...

    In case that i have a default value for a site column which is used in a content type - i want to set it in the content type level.

    The problem is that when i edit the content type and try to edit the column - it opens the site column details (and since it's a site column general definition it set the default values in all the content types that use that site column...)


    keren tsur
    Wednesday, December 28, 2011 2:46 PM
  • Hi Keren -

    You're not going to be able to set two different default values for the same Site Column that is used in two different content types. You can, however, set the default value at the list level once you assign the content type to be used on a list.

    Hope that helps.

    Ryan


    http://blog.randomdust.com
    • Marked as answer by GuYuming Thursday, December 29, 2011 3:44 AM
    • Unmarked as answer by GuYuming Friday, December 30, 2011 1:32 AM
    • Marked as answer by GuYuming Friday, December 30, 2011 1:32 AM
    Wednesday, December 28, 2011 7:13 PM
  • The thing is that i'm using those content types in the same document library...

    (There is a mapping between content type to a metadata, and that's what i tried to achieve. For example if the Document is a "Design Review" template (that's why i used content type - to set the pptx template...) - The metadata "Type of document" should be "Design Review"...


    keren tsur
    Thursday, December 29, 2011 7:11 AM
  • I have done it  .
    Thursday, December 29, 2011 7:25 AM
  • As a workaround, you can use ContentType field in SharePoint designer workflow, you can update some text field value to the ContentType field with a workflow.
    Thursday, December 29, 2011 7:55 AM
  • done what? how?
    keren tsur
    Thursday, December 29, 2011 9:35 AM
  • The thing is that i'm using those content types in the same document library...

    (There is a mapping between content type to a metadata, and that's what i tried to achieve. For example if the Document is a "Design Review" template (that's why i used content type - to set the pptx template...) - The metadata "Type of document" should be "Design Review"...


    keren tsur
    Custom code is going to be your only option, then. Probably an event receiver on the library, or a workflow on the content type, that updates the value of that column programatically.

    http://blog.randomdust.com
    • Marked as answer by GuYuming Friday, December 30, 2011 1:32 AM
    Thursday, December 29, 2011 6:39 PM