3

I have the following:-

  1. Team site collection, which have a content type named “Shared CT”, with fields such as ID, title, name, description, etc…
  2. Inside the Team site collection I have two sub sites; subsiteA + subsiteB
  3. Each sub site has its own CT that has the “Shared CT” as its parent.
  4. Now inside subsiteA’s CT it have a site column named “User Support delivery Risk/issue owner”
  5. While on subsiteB’s CT it have a site column named “Technical Delivery Risk/Issue owner”.

Now I added a new Content Query web part inside the site collection home page, which query all the content types and I apply two filters as follow:-

enter image description here

Now the above will not return any item, but if i remove any of the filters the web part will return results correctly. But having these 2 filters together will prevent any item from being displayed.

Now I searched for what might be causing this problem, and I find that having the two filters as site columns that are defined inside different CT is the problem, since in my case any item inside the subsites will have either the “User Support delivery Risk/issue owner” column or “Technical delivery Risk/issue owner” column but not both of them.

I was able to fix this by adding the “User Support delivery Risk/issue owner” & “Technical delivery Risk/issue owner” columns inside the shared CT, and then I hide it from the un-related subsite CT.so in this way any item will have the 2 site columns where one of the site columns will be hidden...Now the content query web part worked correctly after adding the site columns to the shared CT..

Now I did this test on our test server, but I would think twice before doing such changes inside the live server, as I find it risky to add these columns to the shared CT and then define them as hidden on the un-related child CT. so my question is; if I can have my Content Query web part do the filter correctly without having to modify my CTs ? Thanks

EDIT

i wrote the following query :-

<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>

where i am providing the CT ids & the column internal names, but this will not return any result. although i am having many items that have the defined CTs and the related site column =is equal to the login user ? can anyone adivce ? Beside this i wrote the above query inside the CAML query tool and i used the SP object model, but the query did not return any results also..

enter image description here

---------EDIT 2-------

now for testing purposes i tried the following inside the web part's QueryOverride tag. where i specify to use the CT names instead of their ids:-

<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>

and it showed all the items that are defined inside the specified CTs.which is fine.

but if i try to replace the above to check for site columns , then i will not get any result. for example this CAML query will not show any results:-

<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>

now even if i use inner <And></And> tags for the query that is working well, the query will stop working. for example the following will not return any results :-

<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>

now i am not sure why the first query worked , while the second and third ones did not work ? and at the end is there a way to filter the list items to be as follow:-

  • have CT A + site column A = login user + status= "in progress"

OR

  • have CT B + site column B = login user+ status ="in progress"

-- EDIT 3 ---

now i provided the first 32 characters of my site columns internal names, since seems SP will trim long site columns names, so my final query looks as follow, but still not results is being returned.

<![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><Eq><FieldRef Name="Technical_x0020_Delivery_x0020_T" LookupId="TRUE" /><Value Type="Lookup"><UserID /></Value></Eq></And><And><Eq><FieldRef Name="ContentType"/><Value Type="Computed">Business Functions User Support Delivery Risk Issue</Value></Eq><Eq><FieldRef Name="User_x0020_Support_x0020_Deliver" LookupId="TRUE" /><Value Type="Lookup"><UserID /></Value></Eq></And></Or></Where>]]>

1 Answer 1

1

QueryOverride property of CQWP can be used in this case. The query will use OR between two content types and will use AND to check the current logged in user. Query Example:

<Where>
  <Or>
     <And>
        <Eq>
           <FieldRef Name='ContentType' />
           <Value Type='Computed'>CT1</Value>
        </Eq>
        <Eq>
           <FieldRef Name='User Support delivery Risk/issue owner' />
           <Value Type="Integer"><UserID Type="Integer" /></Value>
        </Eq>
     </And>
     <And>
        <Eq>
           <FieldRef Name='ContentType' />
           <Value Type='Computed'>CT2</Value>
        </Eq>
        <Eq>
           <FieldRef Name='Technical Delivery Risk/Issue owner' />
           <Value Type="Integer"><UserID Type="Integer" /></Value>
        </Eq>
     </And>
  </Or>
</Where>

See this for more information: QueryOverride Filter data based on multiple content types

Update based on Edit 3 In order to check what column internal name is used for your long display names, you may write a simple console app to check that. Or you may also create a filtered view using those columns in a list. Then open the view using SPManager and check what query has been generated. The query will contain the field names.

14
  • thanks a lot for the helpful rely. now how i can apply this query ? can i apply it directly inside the CQWP interface ? or i need to export the web part, open/edit it inside SP designer , then add the web part inside my site ??
    – John John
    Nov 12, 2015 at 9:04
  • i edited the web part inside SP designer and i added the custom query, but when i add the web part to the page , and i edit the web part properties to see its settings , i got the following error " Some properties in this Web Part are not available because they are configured to have fixed values. "
    – John John
    Nov 12, 2015 at 9:30
  • 1
    The webpart needs to be exported. Moreover, queryoverrides chnages cannot be seen from the UI. Nov 12, 2015 at 9:47
  • 1
    yes it does. I also have it installed on SP 2013 Nov 13, 2015 at 2:14
  • 1
    @johnG, see my updated answer Nov 20, 2015 at 3:19

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.