Skip Ribbon Commands
Skip to main content

Laura Rogers @WonderLaura

:

Quick Launch

Laura Rogers @WonderLaura > Posts > InfoPath – Query Specific SharePoint List Data
Hi everyone,
My blog now has a new URL!
You can now find me at http://www.wonderlaura.com
August 01
InfoPath – Query Specific SharePoint List Data

With InfoPath and SharePoint 2010, one of the awesome new capabilities is that you can query specific SharePoint list data from data connections that receive from SharePoint lists and libraries.  This applies to all versions of SharePoint 2010 and Office 365, and is compatible with BOTH client based and browser-based forms.

Back in the old days in SharePoint 2007, when you created a data connection in InfoPath to receive SharePoint list data, you couldn’t specify what data to query.  Whichever list you were retrieving, by default, you would get whatever is shown in the default view of that list.  You could do filters on the information once it was queried, but there wasn’t much that could be done as far as a specific query.

Here’s how you do it in InfoPath 2010 with SharePoint 2010.  the example will be a list of regions and a list of states per region, with a cascading drop-down.  This method is MUCH more efficient because you can query only what you need and not the whole list.  Setup:

  • There are two lists: Regions and States, both custom lists. 
  • Regions has one field called Region, just a text field.
  • States has two fields:  Region is a lookup to the region field in the list of regions, and State a text field.  The states list is much longer than the regions.

ch5[147]ch5[160]

In my InfoPath form called “New Employees”, the goal will be to have a cascading drop-down so that when a region is selected, the list of states in that region will be shown in the next drop-down box.  This can be a SharePoint list (customized with InfoPath) or a form library form.

In the “new employee” example InfoPath form, create a region field and a state field, both as text.  I’ll just focus on these two fields in the steps.

  1. 1.  In InfoPath, create a data connection to receive data from the regions list.  Click this button on the Data tab:
    ch5[161]
  2. For the SharePoint site details, use the URL of the SharePoint site where the regions and states lists are.  Click Next.
  3. From the list of available lists and libraries, select the Regions list.  Click Next.
    ch5[177]
  4. From the list of fields, put a check box next to Region and sort Ascending.  Click Next.
    ch5[189]
  5. Click next on the offline data screen, and click Finish.
  6. Create another data connection to receive from the other list, States.
    ch5[161]
  7. Repeat steps 1 through 3, selecting the States list this time.  From the list of fields, put checkboxes next to Region and State, and sort by state ascending.  Click Next.
    ch5[191]
  8. Click Next on the offline query screen.
  9. This is important, UNCHECK the box to automatically retrieve the data when the form is opened.  In general, it is a best practice to only query data from other lists when it is needed, and not every time the form is opened.  This step is one of the keys to the reason that this method is going to be more efficient.  Click Finish.
    ch5[193]
  10. Place the Region and State fields on the form as drop-down boxes.
    ch5[194]
  11. For the Regions drop-down box, set it up like this. Be sure to set the value as ID and the Display name as title.
    ch5[195]
  12. For the States drop-down box, set it up like this.
    ch5[196]
  13. In the Fields pane on the right, click Advanced View.  let’s take a look at the structure so you’ll understand it.  Change the Fields drop-down to States.  See, there are the query fields, and then there are the data fields.  The data fields will contain the list of states that is retrieved.
    ch5[197]
  14. Now, the trick here will be to query the states list after a region is selected.  So, a rule will be created on the Regions drop-down, which gets triggered right when a value is selected.  Double-click the Regions box, and click the Manage Rules button in the ribbon.
  15. In the rules pane, click the New button and choose Action.  For the first action, click the Add button and choose Set a Field’s Value
  16. For the FIELD, Set the Query value of the Region field in the States list.  (We want to query that list where Region = the region they selected in the Region drop-down box.)
    ch5[198]
  17. For the Value, select the Main data source, and the Region field.
    ch5[199]
    ch5[200]
  18. Click OK.
    ch5[201]
  19. In the Rules pane, click the Add button to add another action.  Pick the action called Query for Data.
  20. Pick States and click OK.
    ch5[202]
  21. Preview the form.  Pick a Region from the drop-down and then choose the States drop-down and notice that it will only show the states in that region.

Again, this is much more efficient than querying the entirety of all data connections each time the form is opened.  The States data connection was set to NOT retrieve data each time the form is opened, and then when it does retrieve data, only a small subset is queried. 

 

Comments

paulfaultner

Laura- does this work if you have a multi-select for the second list?
Shane YoungNo presence information on 8/2/2011 10:48 AM

Paul Perry

Great article - Thanks!  Could you cascade over multiple lists, like, say, Country, Region, City? Is there a limit to the number of data connections you can use in an InfoPath form?  Thanks!  P
Shane YoungNo presence information on 8/4/2011 9:04 AM

Laura

PaulF, No, you'd have to just pull in the whole list and then do a filter rule (formatting rule to hide) on the list, for "contains".  Paul P, Yes.  No, no limit that I've ever encountered.  I've created over 100 before in one form.
Laura RogersNo presence information on 8/8/2011 5:33 PM

Paul P

Thanks for the reply Laura :)  One other thing: If I wanted to do this, but in reverse, i.e. selecting a state and have the region auto-pick, could that be done, without changing the lists? I have an equivalent to the Regions list lookup, but not everyone uses them, hence doesn't always know which one to pick, but the States equivalent list is fully known, so they want to look "back" to the region after selecting the State.  Or can I simply use the Region field in the States List in another field somehow?  Thanks again!  P
Shane YoungNo presence information on 9/1/2011 4:34 AM

Greg Mc

I have a list active projects with a project ID called APLookUp. I then have a list of all my projects called AllProjects.  I have a form that I use to poll the active project list of which one gets selected by the user. I then want the balance of fields to use that ID to fill in the remaining fields for the user. I can't seem to get your concept to work for me. Would/should the process you describe work exactly the same for auto fillin?
Shane YoungNo presence information on 9/2/2011 3:38 PM

Laura

Paul, Sure, you can do it that way also.  Create a rule on the state dropdown that will set the query value on the other list's data connection, and then query the other data connection for just the items that match that state.  Greg, For "auto fillin", after you query to get the specific information, you'd have to use the "set field value" to set your fields to the values from the list you just queried. 
Laura RogersNo presence information on 9/3/2011 8:52 PM

Chris

Hi Laura, You were helping me on the msdn forums with autofilling some text boxes with the data the users inputted the month before.    http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010customization/thread/e5e656cc-8096-4ac3-b533-2eec0bf8e04c  I'm stuck,  I can't seem to get just the data from the user inputted in the people picker.   Could you clarify a couple things for me on the thread?     I think I'm close, but missing something that's causing it to not work.
Shane YoungNo presence information on 9/19/2011 12:20 PM

George

I have a project in which I'm need to have users select from a column of IDs from a problems list. Once they select the ID they need to see the directions to fix vulnerabilities from another list. In the problems list the columns are ID, Category, problem description. The List containing the Fix contains Category field, and fix description field. How do I map the ID field and/or category field of the problem list to display the description field in the Fixes List?
Shane YoungNo presence information on 9/27/2011 10:48 PM

Laura

George, Create a new field called Category, as a text field. Create an action rule on the drop-down box where they're selecting the ID.  Here are the actions in order: 1. Set a field's value. Set the new Category field to the value of the category where the ID matches the ID that they just selected in the drop-down box.  Create a new rule on the new category field (which doesn't have to be showing on your form at all, by the way) 1. set a field's value.  Set the QUERY value for the Category in the Fix list to the currently selected value of the Category field. 2. Query the fix list.  Your fix list can be showing just as a repeating table on the form if you'd like.
Laura RogersNo presence information on 10/11/2011 11:35 AM

Michael B

Laura I love your blog. I use it nearly every week for some great SP info.  From this example, (using SP 2010) I am trying to get my States lookup List to autopopulate the Regions lookup column using a Workflow from the Regions List. I am using Create item in a list in the WF, but I get a coercian error. Any thoughts?
Shane YoungNo presence information on 10/19/2011 11:13 AM

Laura

Michael, Usually a coercian error means that the value of a field is the wrong type of value than the field needs.  Try this: Use the create item action, and only use one of the fields at a time.  Try running the workflow once with each field one at a time, and then that should help you find the culprit.
Laura RogersNo presence information on 10/20/2011 9:43 PM

Michael B

Laura, your suggestion created an extra item in my list, but helped me to narrow down what was and what wasn't working. I updated my create Item action (correctly) and viola! worked like a charm. Now both items are updated correctly in the same item.  Thanks!
Shane YoungNo presence information on 10/21/2011 11:34 AM

Matt

I've tried this and it works, but I noticed that after submitting this, the Region value in the list becomes a numeric number (1, 2, etc). I'm assuming this is the ID or the region.   How do you get around this? I've tried to tweak the value in the field properties and it screws up the query connection.
Shane YoungNo presence information on 10/24/2011 11:33 AM

Laura

Matt, You can create another field in that case.  You'd have to have one field (the drop-down) that stores the value (ID) and another would have to store the Name of it.  So, create another field, you can call it RegionName, click to select the Region drop-down box, and create an action rule: Set a field's value: Field: RegionName Value: (select the data connection) select the name of Region, and do a filter where ID is equal to your field in the Main data source called Region.  Then, the new RegionName field is the one you can promote to SharePoint as a column.
Laura RogersNo presence information on 11/11/2011 7:01 PM

Jason Scott

It works! But I noticed that if you leave Region dropdown as blank, the State dropdown has all the states returned from the list. Is there any way to prevent this?
Shane YoungNo presence information on 11/23/2011 2:33 PM

Sabin

Hello Laura, Thank You for the post, i am a regular visitor. I have a scenario if you can help me with that. I have a list name Inventory where i have following columns: Inventory ID: ID Device Category:dropdown(medical equipment, electronics, imaging equipment) Device Name: dropdown( .........)  Device Category and Device Name are cascading dropdowns.  Other columns are: Serial Number:number Pixel :number storage size:number zoom:number warranty info:date assigned to:people picker inventory status:dropdown  Is there a way where if i select Imaging Device from Device Category dropdown will enable columns Pixel, Zoom. IF selected medical equipment or electronics disabled or greyed out.
Shane YoungNo presence information on 12/20/2011 9:00 AM

Darren Weiss

How do you populate a dropdown list from a text box using infopath web forms.
Shane YoungNo presence information on 12/23/2011 10:28 AM

Laura

Jason, A quick way to do that would be to create a formatting rule on the states list which disables the control if the region field is blank.  Darren, Kind of a vague question.  Not sure what you mean.
Laura RogersNo presence information on 1/6/2012 2:51 PM

Connie

Hello, this was very helpful for me.  I have created a drop-down that I have populating a text box based on the selection in the drop-down.  The problem I am having is if I change the selection, the value in the text box is not updating.
 on 2/22/2012 9:39 AM

Laura

Connie,
You'd need to put a rule on the actual drop-down control, so that it does the query and changes the value, being triggered by the value of the drop-down being changed.
lauraNo presence information on 2/24/2012 11:15 AM

Connie

I am not sure how to create a rule to do a query to change the text box value triggered by the value of the drop-down.  I have a rule that sets the text box value when a selection is made, I am just not entirely sure how I get it to trigger based on the value of the selection made.  The result I get is always the first value in the list.
 on 3/2/2012 7:29 AM

Connie

I just figured it out, thanks for all your help.
 on 3/2/2012 7:40 AM

Chris

Is there a way to query a one to many relationship? I want to query Request # and return all Defect IDs that match that Request #
Example
Request #   |    Defect ID
1                           20
1                           45
2                           6
3                           5
3                           18
3                           22
4                           16
5                           10
 on 3/5/2012 10:41 AM

Patti

Is there a limitation to how many property promotions are created from an InfoPath 2010 form?
I have a form with 600 + fields that I need populated into a sharepoint list using property promotion. Things have been working great and now, when I publish my form, it says it cannot update list or library.

Thank you for a response in advance!
 on 3/6/2012 1:23 PM

Henk Elzinga

Hi Laura,

Thanks for the information so far.
But I am having the following issue.

I have created 4 lists (a,b,c and d)
List a is the starting point. Just one text column.
List b has 2 colums, text field and a lookup column (from list a text column)
With the information I got from you, I was able to get the correct 2 drop down controls values in my form.

But now I want to do the following.
List c has 2 columns, text field and a lookup column (from list b text column)
Now I want to have in my form a 3rd drop down control, depending on the values I have in drop down control 1 and 2.

But so far I did not succeed.
Can you tell me how I can manage this?

Thanks in advance.
 on 3/9/2012 8:12 AM

Laura

Yeah Chris,
At step 16, you'd pick the request # query field.

Hi Patti,
Yeah wow that's an insane amount of fields.  I thought the limit was around 60 fields, but I guess it's 600.

Henk,
Create an action rule on that second drop-down box that will set a query field value and run a query for the values that need to display in the 3rd box, and so on.
lauraNo presence information on 3/14/2012 10:16 PM

Tom

Laura:
PaulF, No, you'd have to just pull in the whole list and then do a filter rule (formatting rule to hide) on the list, for "contains".

If you pull the whole list, the performance will be very slow to load (with thousands of items).  Do you have any suggestion to resolve this problems. I meet the trouble with this.

Thank for your Great article.
 on 3/21/2012 8:18 AM

Laura

Tom,
Are you saying you want to show the whole list, but you don't want to show the whole list because of performance?  If you're worried about performance, then I guess just stick to the original solution and dont' show the whole list?  Am I missing something?
lauraNo presence information on 4/18/2012 8:29 AM

Diddi

i need to fetch the data on particular time of the day from different sheet..right now it is fetching the data at 12:00 AM sinc the date changes i want the data to be fetched at 7:00AM
 on 4/30/2012 10:37 AM

Felix Huachaca

Hi Laura: my english not is perfect sorry..in the step 12 when configure the value y display to title.
When add new item show error why only accept number (ID) and when change in the value to ID is correct save but in the form edit y view form show number ID, i want show display value and not ID value
 on 6/8/2012 2:07 AM

Laura

Diddi,
I recommend just doing that in a workflow.  Dates in InfoPath with formulas are quite a beast.

Felix,
for the display can you just select the title, and for the value, select the ID? Maybe I don't understand the problem.
lauraNo presence information on 6/13/2012 11:00 PM

Cynthia

Hi Laura -
I have an issue working with a large list (8000+ items).  I'm using your cascading dropdown menus (populated by a different list) for the user to select 3 values.  I then use these values to populate the query fields of my large list then run the query.  The list results are filtered down to 3-10 rows using the query fields.  I then display the results in a repeating table.  All was working well until the list grew from 6000 to 8000 items this week, which now exceeds the list view threshold of 7200.  I have partitioned the data into folders (based on Region) and indexed the columns used for filters.  One of the Regions contains over 5000 items and InfoPath throws an error ("exceeds list view threshold") when I query anything in that Region, even though I've used the filters.  If I remove enough records to get the list under the threshold, all is good.  I don't understand why I get this error since I'm filtering the list using the query fields.  Any suggestions how to fix this? 
 on 7/9/2012 12:00 AM

Cynthia

I have been able to resolve the problem by creating a new column that contains the 3 filters contatenated together, then indexed that column, essentially creating a compound index.  But I still don't understand why the query fields didn't trim the list down, so any light you can shed on that would be great!  (Sorry for the multiple posts above - not sure why that's happening!)
 on 7/9/2012 2:11 PM

Laura

Hi Cynthia,
The only time I've seen that not work properly is if a field was blank in the database, I think.  I recommend taking a close look at the records returned and see which ones don't match the query that was sent, then you'd be able to further troubleshoot
lauraNo presence information on 7/18/2012 11:55 AM
​I have disabled any new comments on this, because my blog has moved to a new site.  Please go here: http://www.wonderlaura.com
RSS FeedFacebookYouTube
 

 Our Books for End Users