Querying SP Lists and Libraries by Changing REST URLs Using ListData Service

Querying SP Lists and Libraries by Changing REST URLs Using ListData Service Edit

Background:

In the past, querying SharePoint Lists and Libraries caused a performance hit for large datasets because the form had to load the entire dataset. It turns out SharePoint has it’s own built in solution to this common problem. There is a service called “ListData.svc” which allows URL filtering of data in SharePoint Lists/Libraries. This tutorial will discuss the syntax for filtering data without the performance hit.

Syntax:

Filtering one Column at a Time

http://%5BSiteName%5D/_vti_bin/ListData.svc/%5BListName%5D?$filter=(%5BFieldName%5D eq ‘[Value]’)

Filtering more than one Column at a Time

http://%5BSiteName%5D/_vti_bin/ListData.svc/%5BListName%5D?$filter=((%5BFieldName1%5D eq ‘[Value1]’) and ([FieldName2] eq ‘[Value2]’))

Establishing Original ListData.svc REST Data Connection

Theory:

When establishing a REST Data Connection using ListData.svc, it is important to use a URL that will return more than one result. This is important because you want the Content to have Repeating values to get the most out of your data.

Steps:

  1. From InfoPath, select the Data Ribbon, and select “Data Connections”

 

  1. Click on Add
  2. Select Receive Data
  3. Select Next
  4. Select REST Service
  5. Select Next
  6. Enter a ListData.svc URL which will return more than one result in your dataset as described in the theory section of this tutorial
  7. Select Next
  8. Uncheck “Automatically retrieve data when form is opened”

Note: You should only load your data in the form when you need it. If you load all of your data immediately on form load, then your performance and user experience will suffer.

  1. Select Finish

 

Editing the REST URL

 

Background

By changing the REST URL before you query the data, you can access only the portions of data you need for each action. This increases the performance in your form as well as user experience. It also allows you to perform calculations on limited subsets of data.

 

Theory

Make sure when you change the REST URL you should always ensure these three things are true.

  1. The URL matches what you want to query
  2. The syntax matches the syntax listed in the introduction of this tutorial
  3. The REST URL change and Data Query are performed at the proper time to ensure the right data is available at the right time.

 

Steps

 

  1. Select the trigger for your REST URL Change. This can be anything from a field change to a button click. In most cases however, it will not be performed on FormLoad because nothing has been entered in the form that would precipitate a REST URL Change.
  2. Select the Properties Ribbon, and select Manage Rules
  3. Select New, then select Action
  4. Select Add, Change REST URL
  5. Select the REST URL Data Connection created at the beginning of this tutorial
  6. For this example we are going to concatenate the REST URL using an existing field in our form, so select the Function Button (fx)
  7. Enter the following syntax:

http://%5BSiteName%5D/_vti_bin/ListData.svc/%5BListName%5D?$filter=(%5BFieldName%5D eq ‘[FormColumnName]’)

 

  1. Select OK
  2. In the Rules, select New, Action
  3. Select Add, then select Query for Data
  4. Select the Data Connection which was changed in steps 3-8 above
  5. Select OK
  6. Finished!

 

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.