i want to modify the "Required" property of a field of a list which is associated to a content type.
i've modified the content type and schema of the list, but the "Required" is still set to true, i want it to be optional.
Any idea ?
thanx
sharepoint
i want to modify the "Required" property of a field of a list which is associated to a content type.
i've modified the content type and schema of the list, but the "Required" is still set to true, i want it to be optional.
Any idea ?
thanx
Updating a field in the list will not do anything to the child content types, seeing as each content type in a list not the actual content type itself, but a "silent" child. (inspect the content type id's of the type in the site settings and that of the "same" content type in the list).
use the Site collection's content type collection instead, change the field and properties and then call the content type object's Update method:
SPContentType.Update(true); // true means you want to push any changes made down to all child content types.
i'm working on this with Burt and can share a bit more light on the issue, guidance on what we are doing wrong would be great!!
1) We've created a content type.
E.g
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field ID="{060e50ac-e9c1-4d3c-b1f9-de0bcac300f6}" Name="Price" DisplayName="Price" Type="Text" Required="False" Group="" ColName="Price" StaticName="Price" />
<!-- Parent ContentType: Item (0x01) -->
<!-- set Inherits="FALSE" so the new template is picked up-->
<ContentType ID="0x01000a35b7a7e98c46248e063d79ddd67f6c"
Name="MarketPlaceContentType"
Group=""
Description="Market place item, holds Title, Description, Category etc"
Inherits="FALSE"
Version="0">
<FieldRefs>
<FieldRef ID="{060E50AC-E9C1-4D3C-B1F9-DE0BCAC300F6}" Name="Price" DisplayName="Price" Required="TRUE" />
</FieldRefs>
</ContentType>
</Elements>
2) We've created a list definition using this content type
<
?xml version="1.0" encoding="utf-8"?>
<List xmlns:ows="Microsoft SharePoint" Title="Lists - MarketPlace" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/Lists-MarketPlace"
BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/" NavigateForFormsPages="False" DisableAttachments="true" BrowserFileHandling="permissive" EnableContentTypes="TRUE">
<MetaData>
<ContentTypes>
<ContentType ID="0x01000a35b7a7e98c46248e063d79ddd67f6c" Name="MarketPlaceContentType"
Group="" Description="Market place item, holds Title, Description, Category etc" >
<FieldRefs>
<FieldRef ID="{060E50AC-E9C1-4D3C-B1F9-DE0BCAC300F6}" Name="Price" DisplayName="Price" Required="true" />
</FieldRefs>
</ContentType>
</ContentTypes>
<Fields>
<Field ID="{060e50ac-e9c1-4d3c-b1f9-de0bcac300f6}" Name="Price" DisplayName="Price" Type="Text" Required="True" Group="" />
</Fields>
<Views>
<View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">
<Toolbar Type="Standard" />
<XslLink>main.xsl</XslLink>
<RowLimit Paged="TRUE">30</RowLimit>
<ViewFields>
<FieldRef Name="LinkTitleNoMenu">
</FieldRef>
</ViewFields>
<Query>
<OrderBy>
<FieldRef Name="Modified" Ascending="FALSE">
</FieldRef>
</OrderBy>
</Query>
<ParameterBindings>
<ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_ONET_HOME)" />
</ParameterBindings>
</View>
<View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE"
MobileDefaultView="TRUE"
SetupPath="pages\template\marketpgviewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx" >
<Toolbar Type="Standard" />
<XslLink Default="TRUE">main.xsl</XslLink>
<RowLimit Paged="TRUE">10</RowLimit>
<ViewFields>
<FieldRef Name="MarketplaceCategories" DisplayName="Category"></FieldRef>
<FieldRef Name="LinkTitle" DisplayName="Title"></FieldRef>
<FieldRef Name="Author" DisplayName="Name" />
<FieldRef Name="Created" Format="DateOnly" DisplayName="Date"/>
<FieldRef Name="Locations" DisplayName="Location"></FieldRef>
<FieldRef Name="MarketplaceItemExpiryDate" DisplayName="Expiry Date" Format="DateOnly"></FieldRef>
</ViewFields>
<Query>
<OrderBy>
<FieldRef Name="ID" Ascending="False" />
</OrderBy>
</Query>
<ParameterBindings>
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
</ParameterBindings>
</View>
<View BaseViewID="2" Type="HTML" WebPartZoneID="Main" DisplayName="Items By Category" DefaultView="false" MobileView="TRUE"
MobileDefaultView="TRUE"
SetupPath="pages\template\marketpgviewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="ItemsByCategory.aspx" >
<Toolbar Type="Standard" />
<XslLink Default="TRUE">main.xsl</XslLink>
<RowLimit Paged="TRUE">10</RowLimit>
<ViewFields>
<FieldRef Name="LinkTitle" DisplayName="Title"></FieldRef>
<FieldRef Name="Price"/>
</ViewFields>
<Query>
<Where>
<Eq>
<FieldRef Name="MarketplaceCategories" />
<Value Type="Text">{MarketplaceCategories}</Value>
</Eq>
</Where>
<OrderBy>
<FieldRef Name="Created" Ascending="False" />
</OrderBy>
</Query>
<ParameterBindings>
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
<ParameterBinding Name="MarketplaceCategories" Location="Control(tcCategories, SelectedItem)"/>
</ParameterBindings>
</View>
</Views>
<Forms>
<Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main"/>
<Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
<Form Type="DisplayForm" Url="CustomDisplayForm.aspx" SetupPath="features\$SharePoint.Feature.DeploymentPath$\MarketPlace\displayitem.aspx" UseLegacyForm="true" WebPartZoneID="Main" Template="MarketPlaceDisplayForm"/>
</Forms>
</MetaData>
</List>
3) Our content types have various fields that we want to amend their attributes but we are unable to update them easily.
Any pointers on what we are doing wrong would be great !!!!
Best Answer
Try like this:
Don't forget to add some exception handling.