Reporting Services retrieve data from any Sharepoint list

I am trying to create an SSRS (2008R2) report based on a Sharepoint (2010) list. The main problem is that the List on which the report is run must be a parameter of the report. I know what the structure of the list would be, but a sharepoint site might contain multiple instances of this structure, and when the report runs, the user must select the name of the list. In addition, the report has two date parameters, MinDateTime and MaxDateTime, and only selects records with times between the two.

From what I can tell, there are at least two approaches to building a report:

  • Use a Sharepoint list data source and write a Dataset query in CAML, point the site to the DataSource for SSRS to handle the rest of the details. The problem in this case is that I cannot specify the ListName as a report parameter. The DataSet request looks like this:

    <pre>
       <RSSharePointList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <ListName>BusinessList1</ListName>
              <ViewFields>
                <FieldRef Name="Title" />
                <FieldRef Name="BusinessUnit" />
                <FieldRef Name="ScanDateTime" />
              </ViewFields>
              <Query>
                <Where>
                  <And>
                    <Geq>
                      <FieldRef Name="ScanDateTime" />
                      <Value Type="DateTime">
                        <Parameter Name="MinScanDateTime" />
                      </Value>
                    </Geq>
                    <Leq>
                      <FieldRef Name="ScanDateTime" />
                      <Value Type="DateTime">
                        <Parameter Name="MaxScanDateTime" />
                      </Value>
                    </Leq>
                  </And>
                </Where>
              </Query>
            </RSSharePointList>
    
          

  • Use XML datasource and write Dataset query in soap-readable XML, go directly to web service / _vti_bin / lists.asmx. The request should look something like this (including the list name as a parameter). However, I couldn't get it to work with Date parameters. Where should they be added?

     <pre>  
       <Query>
          <SoapAction>http://schemas.microsoft.com/sharepoint/soap/GetListItems</SoapAction>
       <Method Namespace="http://schemas.microsoft.com/sharepoint/soap/" Name="GetListItems">
          <Parameters>
             <Parameter Name="listName">
                <DefaultValue>BusinessList1</DefaultValue>
             </Parameter>
             <Parameter Name="viewFields">         
                  <ViewFields>
                    <FieldRef Name="Title" />
                    <FieldRef Name="BusinessUnit" />
                    <FieldRef Name="ScanDateTime" />
                 </ViewFields>
             </Parameter>
          </Parameters>
       </Method>
       <ElementPath IgnoreNamespaces="True">*</ElementPath>
    </Query>
    
          

Any direction would be great. Thank,

+3


source to share


1 answer


You can use option 1 by writing the query as an expression. Create a long string with a parameter in the middle. You need a separate request to provide a list of BusinessLists parameters.

The expression will look like this:

="<pre>
   <RSSharePointList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <ListName>"

& Parameters!BusinessList.value & 

"</ListName>
          <ViewFields>
            <FieldRef Name="Title" />
            <FieldRef Name="BusinessUnit" />
            <FieldRef Name="ScanDateTime" />
          </ViewFields>
          <Query>
            <Where>
              <And>
                <Geq>
                  <FieldRef Name="ScanDateTime" />
                  <Value Type="DateTime">
                    <Parameter Name="MinScanDateTime" />
                  </Value>
                </Geq>
                <Leq>
                  <FieldRef Name="ScanDateTime" />
                  <Value Type="DateTime">
                    <Parameter Name="MaxScanDateTime" />
                  </Value>
                </Leq>
              </And>
            </Where>
          </Query>
        </RSSharePointList>"

      

[EDIT]: I'm not sure where the pre tag came from. I missed generating a test report using the sharepoint namelist connection type and it doesn't add that. Check out the MS link for basics .



It indicates that you don't need to specify the fields to return, so a very simple query expression looks like this (adding my added parameter):

="<RSSharePointList xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""><ListName>" & Parameters!List.Value & "</ListName></RSSharePointList>"

      

In my original example above, I didn't mention that you need to escape double quotes in XML by doubling them. I've tested this and it works well.

+1


source







All Articles