Question

Query Multiple Lists

  • 7 February 2023
  • 1 reply
  • 78 views

Badge

Suppose I want to query multiple list in a Site to get a list of all the documents where modified date is before 2018 . How to achieve the same?


1 reply

Userlevel 5
Badge +14

While you technically can get a CAML Query to return the results of multiple lists at once, there is no way to parse that information out via the Query List workflow action. So, you’ll need to make individual Queries per list. 

That said, if you were looking to construct a CAML Query to find all of the documents in a given Library that were before some date, the following should suffice:

<Query>
<Lists>
<List Title="****Target List Name****" />
</Lists>
<ViewFields>
<FieldRef Name="FileLeafRef" />
</ViewFields>
<Where>
<And>
<Lt>
<FieldRef Name="Last_x0020_Modified" />
<Value Type="DateTime">2018-01-01</Value>
</Lt>
<Eq>
<FieldRef Name="ContentType" />
<Value Type="Computed">Document</Value>
</Eq>
</And>
</Where>
<ViewAttributes Scope="RecursiveAll" />
</Query>

 

(Note 1: If you wanted IDs instead of the file names then you could replace the FieldRef Name=”FileLeafRef” with FieldRef Name=”ID” instead)

 

(Note 2: You’ll need to change the ****Target List Name**** to whatever list name that you’re trying to target. Keep the double quotes!)

 

Let me know if that helps or if you need additional help! 

Reply