Click here to Skip to main content
15,884,237 members
Articles / All Topics

How to Display Distinct Data from a Duplicated Data Source in an InfoPath Form

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
20 Oct 2011CPOL1 min read 16.2K  
How to display distinct data from a duplicated data source in an InfoPath form

Sometimes, we have to get data to our InfoPath forms from various sources (From SQL Table, using a Web Service, from a SharePoint list, etc.).

But most of the time, it’s really annoying, if you do not have the option of filtering them directly from the backend (so all the duplicated data will be displayed).

For this example, I will be using the following SQL table with duplicated data:

img_scr_001

So when I connect and retrieve data to an InfoPath form, I will get the following result. (I am using an InfoPath list box to display the data). And if you note, you can see various duplicated values are there in the list.

img_scr_003

And I have used the following connection to retrieve data:

img_scr_002

We can eliminate the duplicated values by applying the following filter to the list box. To do that, follow these steps:

  • Right click on the list box and select ‘List Box Properties’:

    img_scr_004

  • Click on the ‘Select XPath’ button in front of Entries field.

    img_scr_005

  • Click on the filter button on the next screen.

    img_scr_006

  • And add the following filter:
    not(. = ../preceding::<XPath>)

    <XPath>’ is the data source entry of your list box control. To find the XPath, right click that data field and select ‘Copy XPath’.

In my example, the XPath is:

/dfs:myFields/dfs:dataFields/d:temp_table/@Name

But since I am referring to it from ‘/dfs:myFields/dfs:dataFields/’ branch, it should be omitted and only ‘d:temp_table/@Name’ is required.

So the filter should be:

not(. = ../preceding::d:temp_table/@Name)

img_scr_007

Click ‘OK’ on all dialogs and close them. And when you preview your form, you can see only the distinct values.

img_scr_008

Hope this will help you. Smile

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead Air Liquide Industrial Services (Singapore)
Singapore Singapore
My passion lies in building business intelligence and data-based solutions, writing about things I work with and talking about it. New technologies relevant to my line of work interest me and I am often seen playing with early releases of such technologies.

My current role involves architecting and building a variety of data solutions, providing database maintenance and administration support, building the organization’s data practice, and training and mentoring peers.

My aspiration over the next several years is to achieve higher competency and recognition in the field of Data Analytics and move into a career of data science.


Specialities: SQL Server, T-SQL Development, SQL Server Administration, SSRS, SSIS, C#, ASP.Net, Crystal Reports

Comments and Discussions

 
-- There are no messages in this forum --