Defining custom views in a list's schema.xml file
-
09-12-2019 - |
Question
I have create a custom list definition, with a content type.
In the schema.xml, I'd like to define two views :
- All items (the default one, generated by Visual Studio)
- My items (the same view with a filter based on the user id)
When I deploy my list, the two views are actually created, bu the filter I define for the second one disappeared.
Here is the filter I use :
<Query>
<OrderBy>
<FieldRef Name="Modified"
Ascending="FALSE">
</FieldRef>
</OrderBy>
<Where>
<Eq>
<FieldRef Name="AssignedTo" />
<Value Type="Integer">
<UserID />
</Value>
</Eq>
</Where>
</Query>
What is missing ? If I use SPD to create the filter after the deployment, it generates exactly this query.
Don't know if it can help, but here is the whole view definition :
<View BaseViewID="1"
Type="HTML"
WebPartZoneID="Main"
DisplayName="My messages"
DefaultView="TRUE"
MobileView="True"
MobileDefaultView="True"
SetupPath="pages\viewpage.aspx"
ImageUrl="/_layouts/images/announce.png"
Url="MyMessages.aspx">
<Toolbar Type="Standard" />
<XslLink Default="TRUE">mycustomxsl.xsl</XslLink>
<RowLimit Paged="TRUE">30</RowLimit>
<ParameterBindings>
<ParameterBinding Name="NoAnnouncements"
Location="Resource(wss,noXinviewofY_LIST)" />
<ParameterBinding Name="NoAnnouncementsHowTo"
Location="Resource(wss,noXinviewofY_DEFAULT)" />
</ParameterBindings>
<ViewFields>
<FieldRef Name="Attachments">
</FieldRef>
<FieldRef Name="LinkTitle">
</FieldRef>
<FieldRef Name="Modified">
</FieldRef>
</ViewFields>
<Query>
<OrderBy>
<FieldRef Name="Modified"
Ascending="FALSE">
</FieldRef>
</OrderBy>
<Where>
<Eq>
<FieldRef Name="AssignedTo" />
<Value Type="Integer">
<UserID />
</Value>
</Eq>
</Where>
</Query>
</View>
[Edit]: I'm a bit confused with the <View BaseType="1">
attribute. As I want to keep the AllItems view, I have now two views with the same base type. What is exactly the purpose of this attribute ? Am I right to think I can have as many as required view with the same basetype ?
Solution
The BaseViewID must be unique for each view. 1 is the ID of the AllItems view, which has no filters, that's why you can't see your filters.
Refer to this post: http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/52e45ddd-73a8-400f-890c-323a0eaaeccb
OTHER TIPS
BaseViewID
is a confusing name. It should have been named just ViewID
which is what it exactly is.
You BaseViewID must be unique for each view in a list. Try giving the BaseViewID as 3 to your "My Items" View.