3

I am working on a Team Site collection inside SharePoint 2013. and i want to display items that have specific content type + a people or group site column matches the login user. so i did the following steps:-

1- I Add a Content Query web part.

2- I Export the web part.

3- I Edit the web part's QueryOverride tag.

4- i specfiy the following:- here is the full web part content (where i have just edit the QueryOverride tag).:-

    <webParts>
      <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
        <metaData>
          <type name="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
          <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
        </metaData>
        <data>
          <properties>
            <property name="Filter1ChainingOperator" type="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterChainingOperator, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Or</property>
            <property name="FilterOperator1" type="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterFieldQueryOperator, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Eq</property>
            <property name="Direction" type="direction">NotSet</property>
            <property name="FilterOperator3" type="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterFieldQueryOperator, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Eq</property>
            <property name="GroupByDirection" type="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+SortDirection, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Desc</property>
            <property name="DataSourceID" type="string" />
            <property name="ChromeState" type="chromestate">Normal</property>
            <property name="SystemViewFields" type="string" />
            <property name="ListName" type="string" />
            <property name="FilterDisplayValue3" type="string" />
            <property name="FilterDisplayValue2" type="string" />
            <property name="FilterDisplayValue1" type="string" />
            <property name="FilterField1" type="string" />
            <property name="Description" type="string">Displays a dynamic view of content from your site.</property>
            <property name="DataColumnRenames" type="string" />
            <property name="MissingAssembly" type="string">Cannot import this Web Part.</property>
            <property name="PageSize" type="int">-1</property>
            <property name="ViewContentTypeId" type="string" />
            <property name="ParameterBindings" type="string" />
            <property name="HelpUrl" type="string" />
            <property name="AdditionalFilterFields" type="string" />
            <property name="DataMappingViewFields" type="string">{b9e6f3ae-5632-4b13-b636-9d1a2bd67120},Computed;{543bc2cf-1f30-488e-8f25-6fe3b689d9ac},Image;{fa564e0f-0c70-4ab9-b863-0177e6ddd247},Text;{8c06beca-0777-48f7-91c7-6da68bc07b69},DateTime;</property>
            <property name="Title" type="string">B</property>
            <property name="FeedDescription" type="string" />
            <property name="UseCache" type="bool">True</property>
            <property name="XslLink" type="string" null="true" />
            <property name="AutoRefresh" type="bool">False</property>
            <property name="Filter1IsCustomValue" type="bool">False</property>
            <property name="FireInitialRow" type="bool">True</property>
            <property name="FilterValue3" type="string" />
            <property name="SortByFieldType" type="string">DateTime</property>
            <property name="ManualRefresh" type="bool">False</property>
            <property name="HelpMode" type="helpmode">Modeless</property>
            <property name="AllowConnect" type="bool">True</property>
            <property name="ItemStyle" type="string">NoImage</property>
            <property name="SampleData" type="string">&lt;dsQueryResponse&gt;
                        &lt;Rows&gt;
                            &lt;Row Title="Item 1" LinkUrl="http://Item1" Group="Group Header" __begincolumn="True"
__begingroup="True" /&gt;
                            &lt;Row Title="Item 2" LinkUrl="http://Item2" __begincolumn="False" __begingroup="False" /&gt;
                            &lt;Row Title="Item 3" LinkUrl="http://Item3" __begincolumn="False" __begingroup="False" /&gt;
                        &lt;/Rows&gt;
                        &lt;/dsQueryResponse&gt;</property>
            <property name="FilterIncludeChildren2" type="bool">False</property>
            <property name="XmlDefinitionLink" type="string" />
            <property name="ServerTemplate" type="string">1100</property>
            <property name="TitleUrl" type="string" />
            <property name="CommonViewFields" type="string" />
            <property name="QueryOverride" type="string" >
             <![CDATA[
            <Where>
      <Or>
         <And>
            <Eq>
               <FieldRef Name="ContentTypeId" /> <Value Type="ContentTypeId">0x01030039A425F609A70A44BA580AF4A69CB18802</Value>
            </Eq>
            <Eq>
               <FieldRef Name="Technical_x0020_Delivery_x0020_Team" LookupId="TRUE" />
        <Value Type="Integer"><UserID /></Value>
            </Eq>
         </And>
         <And>
            <Eq>
               <FieldRef Name="ContentTypeId" /> <Value Type="ContentTypeId">0x01030039A425F609A70A44BA580AF4A69CB18803</Value>
            </Eq>
            <Eq>
               <FieldRef Name="User_x0020_Support_x0020_Delivery_x0020_Team" LookupId="TRUE" />
        <Value Type="Integer"><UserID /></Value>
            </Eq>
         </And>
      </Or>
    </Where>]]>
            </property>
            <property name="DataSourcesString" type="string" />
            <property name="DisplayName" type="string" />
            <property name="ListGuid" type="string" />
            <property name="DataFields" type="string" />
            <property name="ShowWithSampleData" type="bool">False</property>
            <property name="GroupByFieldType" type="string" />
            <property name="Default" type="string" />
            <property name="ViewFlags" type="Microsoft.SharePoint.SPViewFlags, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">None</property>
            <property name="ContentTypeBeginsWithId" type="string" />
            <property name="AllowHide" type="bool">True</property>
            <property name="FeedEnabled" type="bool">False</property>
            <property name="SortBy" type="string">{8c06beca-0777-48f7-91c7-6da68bc07b69}</property>
            <property name="FilterByContextTerm" type="bool">False</property>
            <property name="TitleIconImageUrl" type="string" />
            <property name="PlayMediaInBrowser" type="bool">True</property>
            <property name="ViewFlag" type="string">0</property>
            <property name="Xsl" type="string">&lt;xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cmswrt="http://schemas.microsoft.com/WebPart/v3/Publishing/runtime" exclude-result-prefixes="xsl cmswrt x" &gt; &lt;xsl:import href="/Style Library/XSL Style Sheets/Header.xsl" /&gt; &lt;xsl:import href="/Style Library/XSL Style Sheets/ItemStyle.xsl" /&gt; &lt;xsl:import href="/Style Library/XSL Style Sheets/ContentQueryMain.xsl" /&gt; &lt;/xsl:stylesheet&gt;</property>
            <property name="FilterField2" type="string" />
            <property name="ChromeType" type="chrometype">TitleOnly</property>
            <property name="CacheXslTimeOut" type="int">86400</property>
            <property name="AdditionalGroupAndSortFields" type="string" />
            <property name="UseSQLDataSourcePaging" type="bool">True</property>
            <property name="Height" type="string" />
            <property name="DataMappings" type="string">Description:{8c06beca-0777-48f7-91c7-6da68bc07b69},Created,DateTime;|ImageUrl:{b9e6f3ae-5632-4b13-b636-9d1a2bd67120},EncodedAbsThumbnailUrl,Computed;{543bc2cf-1f30-488e-8f25-6fe3b689d9ac},PublishingRollupImage,Image;|Title:{fa564e0f-0c70-4ab9-b863-0177e6ddd247},Title,Text;|LinkUrl:|</property>
            <property name="ListUrl" type="string" null="true" />
            <property name="ShowUntargetedItems" type="bool">False</property>
            <property name="AllowMinimize" type="bool">True</property>
            <property name="GroupBy" type="string" />
            <property name="FilterIncludeChildren1" type="bool">False</property>
            <property name="BaseType" type="string" />
            <property name="MainXslLink" type="string" />
            <property name="AsyncRefresh" type="bool">False</property>
            <property name="FilterValue1" type="string" />
            <property name="FilterValue2" type="string" />
            <property name="InitialAsyncDataFetch" type="bool">False</property>
            <property name="AutoRefreshInterval" type="int">60</property>
            <property name="Filter3IsCustomValue" type="bool">False</property>
            <property name="GroupStyle" type="string">DefaultHeader</property>
            <property name="AllowZoneChange" type="bool">True</property>
            <property name="FilterIncludeChildren3" type="bool">False</property>
            <property name="EnableOriginalValue" type="bool">False</property>
            <property name="ItemLimit" type="int">15</property>
            <property name="FilterType1" type="string" />
            <property name="UseCopyUtil" type="bool">True</property>
            <property name="FilterType3" type="string" />
            <property name="FilterType2" type="string" />
            <property name="FilterOperator2" type="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterFieldQueryOperator, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Eq</property>
            <property name="PageType" type="Microsoft.SharePoint.PAGETYPE, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">PAGE_NORMALVIEW</property>
            <property name="FilterByAudience" type="bool">False</property>
            <property name="ItemXslLink" type="string" />
            <property name="Hidden" type="bool">False</property>
            <property name="WebUrl" type="string">~sitecollection</property>
            <property name="HeaderXslLink" type="string" />
            <property name="CacheXslStorage" type="bool">True</property>
            <property name="ListsOverride" type="string" />
            <property name="SortByDirection" type="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+SortDirection, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Desc</property>
            <property name="Filter2IsCustomValue" type="bool">False</property>
            <property name="AllowEdit" type="bool">True</property>
            <property name="FeedTitle" type="string" />
            <property name="FilterField3" type="string" />
            <property name="MediaPlayerStyleSource" type="string" null="true" />
            <property name="DisplayColumns" type="int">1</property>
            <property name="Filter2ChainingOperator" type="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart+FilterChainingOperator, Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Or</property>
            <property name="XmlDefinition" type="string" />
            <property name="WebsOverride" type="string" />
            <property name="AllowClose" type="bool">True</property>
            <property name="ContentTypeName" type="string" />
            <property name="ListId" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">00000000-0000-0000-0000-000000000000</property>
            <property name="ExportMode" type="exportmode">All</property>
            <property name="NoDefaultStyle" type="string" />
            <property name="ViewFieldsOverride" type="string" />
            <property name="CatalogIconImageUrl" type="string" />
            <property name="ListDisplayName" type="string" null="true" />
            <property name="Width" type="string" />
          </properties>
        </data>
      </webPart>
    </webParts>

5- i add the web part to my web parts lists , then i edit a page and i add the web part, but i did not get any result. although i have many items that matches the query..

so can anyone adivce on this please ? Thanks

Additional Info:- i got the content type id from the URL , where i access the CT info from the UI and the url showed the following :-

_layouts/15/ManageContentType.aspx?ctype=0x01030039A425F609A70A44BA580AF4A69CB18802

for the site columns i also access the column from the UI, and their internal name looks as follow:-

/_layouts/15/ManageContentTypeField.aspx?ctype=0x01030039A425F609A70A44BA580AF4A69CB18802&Field=Technical%5Fx0020%5FDelivery%5Fx0020%5FTeam&Fid=%7B68bd4d83%2Ddbfa%2D4e0a%2Daf37%2D76c0a0056ae8%7D

----EDIT------

for testing purposes i wrote the following CAML where i define the CT names instead of ids , and it retrieved all the items that have any of these two CTs correctly:-

<property name="QueryOverride" type="string"><![CDATA[<OrderBy><FieldRef Name="Created"  Ascending="FALSE" /></OrderBy><Where><Or><Eq><FieldRef Name="ContentType"/><Value Type="Computed">Business Functions Technical Delivery Risk Issue</Value></Eq><Eq><FieldRef Name="ContentType"/><Value Type="Computed">Business Functions User Support Delivery Risk Issue</Value></Eq></Or></Where>]]></property>

now i changed my query to check if the login user = any of two site columns,, but this will not return any results un-like the above CAML query ? i am really confused on how CAML should work ? this is the most confusing topic i have every worked on in my whole life !!!

<property name="QueryOverride" type="string"><![CDATA[<OrderBy><FieldRef Name="Created"  Ascending="FALSE" /></OrderBy><Where><Or><Eq><FieldRef Name="User_x0020_Support_x0020_Delivery_x0020_Team" LookupId="TRUE" /><Value Type="Integer"><UserID Type="Integer" /></Value></Eq><Eq><FieldRef Name="Technical_x0020_Delivery_x0020_Team" LookupId="TRUE" /><Value Type="Integer"><UserID Type="Integer" /></Value></Eq></Or></Where>]]></property>

---EDIT 2 ---

Now the only query i have it working correctly is this simple query :-

<property name="QueryOverride" type="string"><![CDATA[<OrderBy><FieldRef Name="Created"  Ascending="FALSE" /></OrderBy><Where><Or><Eq><FieldRef Name="ContentType"/><Value Type="Computed">Business Functions Technical Delivery Risk Issue</Value></Eq><Eq><FieldRef Name="ContentType"/><Value Type="Computed">Business Functions User Support Delivery Risk Issue</Value></Eq></Or></Where>]]></property>

but if i add inner <And></And> tags inside it , it will stop work , for example this will not work :-

<property name="QueryOverride" type="string"><![CDATA[<OrderBy><FieldRef Name="Created"  Ascending="FALSE" /></OrderBy><Where><Or><And><Eq><FieldRef Name="ContentType"/><Value Type="Computed">Business Functions Technical Delivery Risk Issue</Value></Eq></And><And><Eq><FieldRef Name="ContentType"/><Value Type="Computed">Business Functions User Support Delivery Risk Issue</Value></Eq></And></Or></Where>]]></property>

but if i remove all the <AND> & </And> tags it will work well .. so can anyone adivce ?

2
  • Try with "contains" rather than "equal".
    – Marko Tica
    Nov 16, 2015 at 12:36
  • Replace <Eq> with <Contains> for both ContentTypeId field in QueryOverride property
    – Marko Tica
    Nov 16, 2015 at 12:41

1 Answer 1

1

Try with ContentTypeId first and add <Query> before <Where> and with Value Type="Text"

    <property name="QueryOverride" type="string" >
             <![CDATA[
<Query>
    <Where>
      <Or>
            <Eq>
               <FieldRef Name="ContentTypeId" /> <Value Type="ContentTypeId">0x01030039A425F609A70A44BA580AF4A69CB18802</Value>
            </Eq>
            <Eq>
               <FieldRef Name="ContentTypeId" /> <Value Type="ContentTypeId">0x01030039A425F609A70A44BA580AF4A69CB18803</Value>
            </Eq>
      </Or>
    </Where>
</Query>]]>
            </property>

If you get results then add that Delivery Team fields.

EDIT

Try remove CDATA and replace < with &lt; and > with &gt;

...and replace "" with ''

So that you have something like this.

<property name="QueryOverride" type="string">&lt;Where&gt;&lt;Or&gt;&lt;Eq&gt;&lt;FieldRef Name='ContentTypeId' /&gt; &lt;Value Type='ContentTypeId'&gt;0x01030039A425F609A70A44BA580AF4A69CB18802&lt;/Value&gt;&lt;/Eq&gt;&lt;Eq&gt;&lt;FieldRef Name='ContentTypeId' /&gt; &lt;Value Type='ContentTypeId'&gt;0x01030039A425F609A70A44BA580AF4A69CB18803&lt;/Value&gt;&lt;/Eq&gt;&lt;/Or&gt;&lt;/Where&gt;</property>

Add in property CommonViewFields your columns for ex. ContentTypeId;Technical_x0020_Delivery_x0020_Team;User_x0020_Support_x0020_Delivery_x0020_Team

<property name="CommonViewFields" type="string">ContentTypeId;Technical_x0020_Delivery_x0020_Team;User_x0020_Support_x0020_Delivery_x0020_Team</property>

list of internal names http://blogs.msdn.com/b/michael_yeager/archive/2008/11/03/reference-list-for-internal-field-names.aspx

more on link: https://msdn.microsoft.com/en-us/library/aa981241.aspx

EDIT 2

Look at this pages

http://www.sharepointnadeem.com/2011/11/cqwp-queryoverride-filter-data-based-on.html http://blog.riccardocelesti.it/extend-content-query-web-part-with-queryoverride/

Try without spaces all in one line, replace ' with &quot; and add CDATA

<property name="QueryOverride" type="string"><![CDATA[&lt;Where&gt;&lt;Or&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;ContentTypeId&quot;/&gt;&lt;Value Type=&quot;ContentTypeId&quot;&gt;0x01030039A425F609A70A44BA580AF4A69CB18802&lt;/Value&gt;&lt;/Eq&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;ContentTypeId&quot;/&gt;&lt;Value Type=&quot;ContentTypeId&quot;&gt;0x01030039A425F609A70A44BA580AF4A69CB18803&lt;/Value&gt;&lt;/Eq&gt;&lt;/Or&gt;&lt;/Where&gt;]]></property>

Maybe you needed to write CDATA just after QueryOverride without space. Try it.

<property name="QueryOverride" type="string"><![CDATA[<Where>...

Check your columns internal names

&Field=Technical%5Fx0020%5FDelivery%5Fx0020%5FTeam&Fid=%7B6..

EDIT 3

Open powershell as admin and run this script which will tell you internal name of site columns match title "Team" Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

$url = "http://YOURSITE"

$site = new-object Microsoft.SharePoint.SPSite($url)
$web = $site.rootweb.Fields
ForEach ($id in $web)
{
$id | select Title, InternalName | where {$id.Hidden -eq $false} | where {$id.Title -match "Team"}
}
7
  • can you check my edit section please ?
    – John John
    Nov 16, 2015 at 15:44
  • ok i tried this "<property name="QueryOverride" type="string"><![CDATA[<OrderBy><FieldRef Name="Created" Ascending="FALSE" /></OrderBy><Where><Or><Eq><FieldRef Name="Technical%5Fx0020%5FDelivery%5Fx0020%5FTeam" LookupId="TRUE" /><Value Type="Integer"><UserID Type="Integer" /></Value></Eq><Eq><FieldRef Name="User%5Fx0020%5FSupport%5Fx0020%5FDelivery%5Fx0020%5FTeam" LookupId="TRUE" /><Value Type="Integer"><UserID Type="Integer" /></Value></Eq></Or></Where>]]></property>">> but will not work. i think i need to decode the internal names before using them inside my web part is this correct?
    – John John
    Nov 16, 2015 at 15:56
  • i have 2 site columns and i am providing the correct internal names for them as follow:- <property name="QueryOverride" type="string"><![CDATA[<OrderBy><FieldRef Name="Created" Ascending="FALSE" /></OrderBy><Where><Or><Eq><FieldRef Name="User_x0020_Support_x0020_Delivery_x0020_Team" LookupId="TRUE" /><Value Type="Integer"><UserID Type="Integer" /></Value></Eq><Eq><FieldRef Name="Technical_x0020_Delivery_x0020_Team" LookupId="TRUE" /><Value Type="Integer"><UserID Type="Integer" /></Value></Eq></Or></Where>]]></property> ,, where %5F will be translated as "_"
    – John John
    Nov 16, 2015 at 16:02
  • see my last edit
    – Marko Tica
    Nov 16, 2015 at 16:25
  • i am providing the correct site columns internal names,, i already check this script. can you check my "Edit 2 " section , where i got a simple query working ,, but if i use inner <AND> tags inside the <OR> it will stop working,, can u please check edit-2 section,, thanks. as i think the CAML syntax is the problem or not all options are supported in SP.. same as in the first problem, where referencing CT by their ids will not work, but referencing them using their display names worked well..
    – John John
    Nov 16, 2015 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.