in

InfoPath Dev

This Blog

Syndication

Greg Collins

Display Only Unique Options in a List

When list box entries are looked up in either the form's data source or a data connection, you might end up with the user being presented duplicate options. You can correct this, and display only unique options in a list, by using a filter and the appropriate XPath.

In this task we will create a filtered drop-down list box that presents the user with a unique set of options. Let's start by designing a new blank form.

Add the controls to the view:

  1. Open the Controls task pane.
  2. Insert a Drop-Down List Box into the view.
  3. Insert a 1 column Repeating Table into the view.
  4. Type Source Values into the header row of the repeating table.

Populate the drop-down list box:

  1. Double-click the drop-down list box.
  2. On the Data tab of the Drop-Down List Box Properties dialog box, select Look Up Values In The Form's Data Source.
  3. Click the Select XPath button to the right of the Entries text box, and then select group1/group2/field2.

Filter for unique values:

  1. Click Filter Data, and then click Add.
  2. In the Specify Filter Conditions dialog box, select The Expression from the first drop-down list, and then type the following expression (as shown in Figure 1):

not(. = ../preceding::my:group2/my:field2)


Figure 1. Filtering list options to display only unique values.

  1. Click OK four times.

Try it:

Preview the form. Add several rows of values to the repeating table, making sure that some of the values are duplicates, and then examine the options in the drop-down list. As shown in Figure 2, the drop-down list only displays unique values as the XPath expression prevented duplicate values from being added to the list.

Figure 2. The filtered list box displays only unique options.

InfoPath applies our filter as it steps through the values in repeating table to add them to the list box entries. The XPath expression in our filter checks to see whether a my:field2 value in a previous row (my:group2) is identical to the my:field2 value in the current row. If it is, the value is not added to the list.

©2005 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

Comments

 

zaphi said:

Hi Greg

Sorry, but I have done exactly this sampler like explained, but I get duplicates in the list.

I have infoPath 2003 SP2, and work in german.

Can you explain it?

Best regards.

Philippe

November 30, 2007 7:45 AM
 

zaphi said:

Hi Greg

Sorry, I had a problem with the german syntax. I could correct it, and it works correctly.

Your how-to is very good!

Best regards.

Philippe

December 3, 2007 12:46 AM
 

Greg Collins said:

Thank you zaphi, I'm glad to hear you got it working!

January 15, 2008 9:53 AM
 

Lalato said:

Will this same logic work for a secondary data source?  I would like to do this with an XML file, but I keep getting duplicates.

Thanks,

--sam

April 14, 2008 10:05 AM
 

Lalato said:

Never mind... I figured out my problem.  Thanks for the great info.

--sam

April 14, 2008 10:08 AM
 

rab2k said:

Greg - Could you provide the syntax for pulling unique values from a SharePoint list?  I am using a Sharepoint List with duplicate values to populate the InfoPath Sharepoint dropdown, but would like it to only display unique values.  

July 7, 2008 10:26 PM
 

dave_2k8 said:

rab2k - Did you ever find a solution to you issue with pulling unique values from a SharePoint list.

I am looking to do the same - but cannot find a way to do it.

Thanks..Dave

December 11, 2008 3:12 AM

About Greg Collins

I am a Microsoft MVP.

I developed many of the Microsoft sample solutions that shipped with InfoPath v1 and currently develop InfoPath solutions for a living, exploiting my strong background in programming, Web development and graphic design.

I developed the original InfoPathDev Web site and numerous other Web sites. I enjoy spending time with my family, the outdoors, digital photography, graphic design and desktop publishing.

Check out my web site at http://www.braintrove.com
Copyright © 2003-2007 Qdabra Software. All rights reserved.
View our Terms of Use.